I am trying return a slice of an xml-parsed nested list but I can't work out the syntax. Essentially I'm trying isolate all the list between the first and last horizontal rules. I have made a kludge which seems to work, but I would like to know how to do this correctly.
Here is what I have come up with so far:
Code: Select all
;Try to open the file given in the main args
(if (not (set 'myxml (read-file (main-args -1))))
((println (rest (sys-error)))(exit 1)))
;Set the flags so that the XML parser doesn't return "Element" "CType", etc.
(xml-type-tags nil nil nil nil)
;Hopefully parse the text into an s-expression list. The numbers at the end of xml-parse are the parser settings.
(if (not (set 'myxml (xml-parse myxml (+ 1 2 8))))
((println (first (xml-error))) (exit 1)))
;Isolate the <body>
(set 'myxml (myxml 0 2))
;Discard everything before the first <HR>
(set 'myxml (slice myxml (inc (first (ref 'HR myxml)))))
;Discard everything after the remaining <HR>
(set 'myxml (slice myxml 0 (first (ref 'HR myxml))))
;Output to console to be piped or redirected
(println myxml)
(exit)
-Peter Weston