forked from frodef/pithy-xml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
53 lines (38 loc) · 1.95 KB
/
README
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
Read and write XML as lisp objects. Syntax somewhat similar to that of
CL-WHO.
Disregarding interning (see below), an XML element <foo a=1>...</foo>
is represented in either of two ways:
(:foo :a 1 ...) or ((:foo :a 1) ...)
READ-XML will always return the latter form, because it is more
consistent for processing. The former is perhaps more convenient to
write: the element's content starts with the first
non-keyword/value-pair.
Tag names etc. are mapped to (and from) lisp symbols. XML namespaces
are represented as lisp packages, into which symbols are
interned. Note that XML namespaces are named by (globally unique)
URLs, although you'll probably find it convenient to provide
short-hand names (see DEFINE-XML-NAMESPACE). Read/print-xml will keep
track of namespace bindings. In the following example, the same "foo"
is referenced in the two XML fragments, using first "qualified names"
and second "namespace defaulting":
> (equal (cdr (read-xml "<bar xmlns:nn='http://blah'><nn:foo>42</nn:foo></bar>"))
(print (cdr (read-xml "<bar xmlns='http://blah'><foo>42</foo></bar>"))))
((NN:FOO "42"))
=> T
XML comments are represented as (pithy-xml:xml-comment "text"). If you
don't care about XML namespaces, use keywords. For example:
PITHY-XML> (read-xml (print (print-xml '(:element :attribute 1 (:sub-element 42)))))
"<Element attribute='1'>
<SubElement>42</SubElement>
</Element>"
=> (((:ELEMENT :ATTRIBUTE "1") ((:SUB-ELEMENT) "42")))
Here's an example of using DEFINE-XML-NAMESPACE-BY-SCHEMA:
(define-xml-namespace-by-schema
xmldsig
"http://www.w3.org/2000/09/xmldsig#"
"~/src/xml-schemas/xmldsig-core-schema.xsd"
(:acronyms "HMAC" "SKI" "CRL" "PGP" "SPKI" "DSA" "RSA" "ID")
(:documentation "http://www.w3.org/TR/xmldsig-core/"))
Pithy-XML does not support all features of XML. There are various
issues with defining entities, CDATA, etc that I've yet to have use
for, and therefore have not implemented. Feel free to improve on this.