Skip to content
/ esxml Public
forked from tali713/esxml

An elisp library for working with xml, esxml and sxml.

Notifications You must be signed in to change notification settings

snogge/esxml

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Read Me

This library was created to fascilitate quickly building web pages, though it also includes tools for working with parsed xml

Code Generation with esxml.el

This library provides to formats for xml code generation. The primary form is esxml. esxml is the form that is returned by such functions as libxml-parse-xml-region and is used internally by emacs in many xml related libraries.

A brief example

The following is a very simple esxml document, paths are handled directly, via a case statement. While this is not good practice, this is meant to be a very simple example.

sxml example

(let ((count 0))
  (defun sxml-demo (httpcon)
    (incf count)
    (case (intern (elnode-http-pathinfo httpcon))
      (/messages (with-current-buffer "*Messages*"
                   (sxml-to-xml `(html (body (pre ,(buffer-string)))))))

      (t (sxml-to-xml
          `(html
            (body
             (h1 "Hello from Emacs!") (br)
             "Trying to visit " ,(format "%s" (elnode-http-pathinfo httpcon)) (br)
             "Visit " (a (@ (href "/messages")) "messages") " to see the *Messages* buffer." (br)
             "Have been visited " ,(format "%s" count) " times since last started.")))))))

This outputs the following HTML:

<html >
  <body >
    <h1 >Hello from Emacs!</h1><br />
    Trying to visit /anywhere<br />
    Visit <a href="/messages">messages</a> to see the *Messages* buffer.<br />
    Have been visited 1 times since last started.
  </body>
</html>

esxml example

(let ((count 0))
  (defun esxml-demo (httpcon)
    (incf count)
    (case (intern (elnode-http-pathinfo httpcon))
      (/messages (with-current-buffer "*Messages*"
                   (esxml-to-xml `(html () (body () (pre () ,(buffer-string)))))))
      
      (t (esxml-to-xml
          `(html ()
                 (body ()
                       (h1 () "Hello from Emacs!")
                       (br) "Trying to visit " ,(format "%s" (elnode-http-pathinfo httpcon))
                       (br)  "Visit " (a ((href . "/messages")) "messages")  " to see the *Messages* buffer."
                       (br) "Have been visited " ,(format "%s" count) " times since last started.")))))))

Advanced examples

A standard page generator

Extracting Data from XML

TODO

About

An elisp library for working with xml, esxml and sxml.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Emacs Lisp 100.0%