blob: 45e412ff2c7b7a17004b5fde341f05fb11b666f2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
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
#+BEGIN_SRC elisp
(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.")))))))
#+END_SRC
This outputs the following HTML:
#+BEGIN_SRC
<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>
#+END_SRC
*** esxml example
#+BEGIN_SRC elisp
(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.")))))))
#+END_SRC
** Advanced examples
*** A standard page generator
* Extracting Data from XML
TODO
|