3 # qa-xml - test newLISP xml-parse, xml-type-tags functions
8 <DATABASE name="example.xml">
9 <!--This is a database of fruits-->
32 ("ELEMENT" "DATABASE" (("name" "example.xml")) (("TEXT" "\n") (
33 "COMMENT" "This is a database of fruits")
35 ("ELEMENT" "FRUIT" () (("TEXT" "\n ") ("ELEMENT" "NAME"
39 ("ELEMENT" "COLOR" () (("TEXT" "red")))
41 ("ELEMENT" "PRICE" () (("TEXT" "0.80")))
44 ("ELEMENT" "FRUIT" () (("TEXT" "\n ") ("ELEMENT" "NAME"
48 ("ELEMENT" "COLOR" () (("TEXT" "orange")))
50 ("ELEMENT" "PRICE" () (("TEXT" "1.00")))
53 ("ELEMENT" "FRUIT" () (("TEXT" "\n ") ("ELEMENT" "NAME"
57 ("ELEMENT" "COLOR" () (("TEXT" "yellow")))
59 ("ELEMENT" "PRICE" () (("TEXT" "0.60")))
65 ("ELEMENT" "DATABASE" (("name" "example.xml")) (("ELEMENT" "FRUIT"
66 (("ELEMENT" "NAME" (("TEXT" "apple"))) ("ELEMENT" "COLOR" ((
68 ("ELEMENT" "PRICE" (("TEXT" "0.80")))))
69 ("ELEMENT" "FRUIT" (("ELEMENT" "NAME" (("TEXT" "orange"))) ("ELEMENT"
72 ("ELEMENT" "PRICE" (("TEXT" "1.00")))))
73 ("ELEMENT" "FRUIT" (("ELEMENT" "NAME" (("TEXT" "banana"))) ("ELEMENT"
76 ("ELEMENT" "PRICE" (("TEXT" "0.60")))))))))
80 (DATABASE ((name "example.xml")) (!-- "This is a database of fruits")
81 (FRUIT (NAME "apple") (COLOR "red") (PRICE "0.80"))
82 (FRUIT (NAME "orange") (COLOR "orange") (PRICE "1.00"))
83 (FRUIT (NAME "banana") (COLOR "yellow") (PRICE "0.60")))))
87 (define (test-xml-parse)
89 (= (xml-type-tags "TEXT" "CDATA" "COMMENT" "ELEMENT")
90 '("TEXT" "CDATA" "COMMENT" "ELEMENT"))
91 (print (= result1 (xml-parse example-xml)) " ")
92 (print (= result2 (xml-parse example-xml (+ 1 2 4))) " ")
93 (xml-type-tags nil 'cdata '!-- nil)
94 (print (= result3 (xml-parse example-xml (+ 1 2 8))) " ")
95 (xml-type-tags nil nil nil nil)
96 (print (= (xml-parse "<msg>Hello World</msg>" (+ 1 2 4 8 16) 'CTX)
97 '((CTX:msg "Hello World"))) " -> ")
102 (println "xml-parse and xml-type-tags OK")
103 (println "ERROR with xml-parse or xml-type-tags"))
108 ;; test callback feature
109 (define (xml-callback s-expr start size)
110 (if (or (= (s-expr 0) 'NAME) (= (s-expr 0) 'COLOR) (= (s-expr 0) 'PRICE))
112 (print "parsed expresson:" s-expr)
113 (println ", source:" (start size example-xml))
118 (println "Testing xml-parse with callback feature")
119 (xml-type-tags nil 'cdata '!-- nil)
120 (xml-parse example-xml (+ 1 2 8) MAIN xml-callback)
122 ; produces this output:
124 parsed expresson:(NAME "apple"), source:<NAME>apple</NAME>
125 parsed expresson:(COLOR "red"), source:<COLOR>red</COLOR>
126 parsed expresson:(PRICE "0.80"), source:<PRICE>0.80</PRICE>
127 parsed expresson:(NAME "orange"), source:<NAME>orange</NAME>
128 parsed expresson:(COLOR "orange"), source:<COLOR>orange</COLOR>
129 parsed expresson:(PRICE "1.00"), source:<PRICE>1.00</PRICE>
130 parsed expresson:(NAME "banana"), source:<NAME>banana</NAME>
131 parsed expresson:(COLOR "yellow"), source:<COLOR>yellow</COLOR>
132 parsed expresson:(PRICE "0.60"), source:<PRICE>0.60</PRICE>