I'm having real problems finding data in the CAPEC XML document. ( 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:
Code: Select all
(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))
Code: Select all
(println (lookup "Attack_Pattern_Catalog" capec))
Now, If I run:
Code: Select all
(set 'capec-categories (lookup "Attack_Pattern_Catalog" capec 2))
(println capec-categories)
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,
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?"Lutz wrote:'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.
I'd love to see some examples that work better than what I'm dealing with right now... :)