-
Notifications
You must be signed in to change notification settings - Fork 8
5.13 XML
Claude Roux edited this page Jan 27, 2022
·
2 revisions
The XML library allows you to traverse an XML structure and query the node values.
It exposes the following methods:
(deflib xml_nodeid (node) Return the node internal id)
(deflib xml_load (pathname) Load an XML document)
(deflib xml_namespace (node) Return the node name space)
(deflib xml_name (node) Return the node name)
(deflib xml_content (node) Return the node content)
(deflib xml_properties (node) Return the node properties)
(deflib xml_line (node) Return the node line number)
(deflib xml_setnodeid (node id) Set an internal numerical value to the current xml node)
(deflib xml_type (node) Return the node type)
(deflib xml_parse (buffer) Load an XML document)
(deflib xml_child (node) Return the first child node)
(deflib xml_next (node) Return the next node)
(deflib xml_parent (node) Return the parent node)
(deflib xml_previous (node) Return the previous node)
(deflib xml_root (doc) Return the root node of the document)
Here is an example of how to use it:
; We load and traverse an xml document
; DO not forget to set your LISPEPATH variable to the directory
; where lispe_xml is located...
; export LISPEPATH=/home/user/lispe/binaries/mac
(use 'lispe_xml)
; we traverse our XML structure
; first the child, then the sisters
; these functions returns 'nil' in case of error
(defun parcours(x id)
(if (nullp x)
nil
(block
(xml_setnodeid x id)
(print "id: " (xml_nodeid x) " ")
(if (eq (xml_name x) "text")
(println (xml_content x))
(println x (xml_line x) (xml_properties x))
)
(parcours (xml_child x) (+ 1 id))
(parcours (xml_next x) (+ 1 id))
)
)
)
; We load our file first
; This instruction creates an xmldoc object
(setq doc (xml_load (+ _current "sentence.xml")))
; The document root is an xmlnode
; this is the first node to start our exploration from
(parcours (xml_root doc) 0)