I have a test XML file called dingy.xml that looks like this:
Code: Select all
<document>
<element name="First" date="4/23/2010">
<data>This is the first element</data>
</element>
<element name="Second" date="4/23/2010">
<data>This is the second element</data>
</element>
</document>
Code: Select all
(define (parse-xml-data str)
(xml-type-tags nil nil nil nil)
(let ((xml (xml-parse str 15)))
(or xml (throw-error (xml-error)))))
(setq parsedlist (parse-xml-data (read-file "./dingy.xml")))
((document (element ((name "First") (date "4/23/2010")) (data "This is the first element")) (element ((name "Second") (date "4/23/2010")) (data "This is the second element"))))
Now, I am able to search and retrieve, say, all items with the type "data" using this code:
Code: Select all
(dolist (el (ref-all 'data parsedlist))
(println (rest (parsedlist (chop el)))))
("This is the first element")
("This is the second element")
This is great! But now my question is this: how could I find all the "field names" (I don't know how better to describe it) without knowing them beforehand? In this XML example, I have a type called "data", which I pass into ref-all by quoting it; 'data. But what if I just want to get a list of all possible elements I could search for? In other words, how could I get a list back that looks like this:
((document) (name) (date) (element) (data))
which is all the different types of element names (field names?) in my XML? My goal for this is to be able to input in any kind of XML file and return back a list of searchable "field names".
In the newLISP introductory guide, it says (pg 156):
I guess what I'm looking for is some way to bring back a list of all the symbols that have been added to the symbol table when I use xml-parse. I wish I could have explained it better. :)You add them up to get the options code number – so 15 (+ 1 2 4 8) uses the first four of these options: suppress unwanted stuff, and translate strings tags to symbols. As a result of this, new symbols have been added to newLISP’s symbol table:
(channel description docs item lastBuildDate link managingEditor rss sxml title version webMaster xml)
These correspond to the string tags in the XML file, and they’ll be useful almost immediately.
Thanks so much for any help you can provide!