Big XML Mess (help)

Started by kanen, June 22, 2010, 11:16:31 AM

Previous topic - Next topic

kanen

newLISP experts,



I'm having real problems finding data in the CAPEC XML document. ( http://capec.mitre.org/data/xml/capec_v1.5.xml">http://capec.mitre.org/data/xml/capec_v1.5.xml )



I've read through everything on the forums and I've tried a bunch of things, but I seem to only be able to dig into the XML if I know what field I'm looking for... and, even then, it's a nightmare to parse.



I feel like I'm missing some obvious way to do a lookup, but I just can't get there...



My code:
(context 'Xml)
(define (Parse xml-string)
  (xml-type-tags nil nil nil nil)
  (set 'rtn-xml (xml-parse xml-string (+ 1 2 4) 'CAPEC)) )

(set 'capec-file (read-file "http://capec.mitre.org/data/xml/capec_v1.5.xml"))
(set 'capec-xml (read-file capec-file))
(set 'capec (Xml:Parse capec-xml))


I can run:
(println (lookup "Attack_Pattern_Catalog" capec))

... and I get the whole XML structure as a big fat list.



Now, If I run:
(set 'capec-categories (lookup "Attack_Pattern_Catalog" capec 2))
(println capec-categories)


I get some XML that seems to make sense, but I still need to be able to reference everything properly. The CAPEC XML structure is just a nested freaking nightmare (as you can see above).



Is there any way to grab one of the items using (lookup <item-name> capec) or is there something else I need to start thinking about? Is there a better way to structure the XML into an assoc or list so I can walk through it or do a lookup in a meaningful way?



Lutz commented to me and said,
Quote from: "Lutz"'lookup' is for one-dimensional flat association lists. Use 'ref' or 'ref-all' they search through deeper nested lists and return and index vector of the element found.



You can then 'chop' off the last index or two to get the bigger enclosing association list.



Start with a smaller example to see how it works.


So, my question is, "Has anyone dealt with XML this complicated (and nested) and do you have an example of how to interact with that XML in newLISP?"



I'd love to see some examples that work better than what I'm dealing with right now... :)
. Kanen Flowers http://kanen.me[/url] .

cormullion

#1
Yes, it can be a nightmare navigating those sxml lists...



I've written a bit about it here: http://en.wikibooks.org/wiki/Introduction_to_newLISP/Working_with_XML">//http://en.wikibooks.org/wiki/Introduction_to_newLISP/Working_with_XML and here http://unbalanced-parentheses.nfshost.com/listlistolist">//http://unbalanced-parentheses.nfshost.com/listlistolist and here http://unbalanced-parentheses.nfshost.com/follwuplistindexing">//http://unbalanced-parentheses.nfshost.com/follwuplistindexing...



There are lots of other techniques to try - using ref with match-style wild-cards, for example.



Also - http://newlispfanclub.alh.net/forum/viewtopic.php?f=16&t=3624">//http://newlispfanclub.alh.net/forum/viewtopic.php?f=16&t=3624 was a recent discussion...







...somewhat in haste... :)