<expr test="5 > 7" />
, CDATA nodes, comments, namespaces, and processing instructions.<?foo bar?>
).<!-- hello world -->
).<![CDATA[ whoa <xml> & other content as text ]]>
).<foo xmlns="bar">
and <wrap xmlns:bar="bar"><bar:kittens/></wrap>
).< > & " '
) and numeric entities (e.g.
) in attributes and text nodes (but—properly—not in comments or CDATA). Properly handles edge cases like &amp;
.SLAXML:dom()
method.doc.type
: the string "document"
doc.name
: the string "#doc"
doc.kids
: an array table of child processing instructions, the root element, and comment nodes.doc.root
: the root element for the documentsomeEl.type
: the string "element"
someEl.name
: the string name of the element (without any namespace prefix)someEl.nsURI
: the namespace URI for this element; nil
if no namespace is appliedsomeEl.attr
: a table of attributes, indexed by name and indexlocal value = someEl.attr['attribute-name']
: any namespace prefix of the attribute is not part of the namelocal someAttr = someEl.attr[1]
: an single attribute table (see below); useful for iterating all attributes of an element, or for disambiguating attributes with the same name in different namespacessomeEl.kids
: an array table of child elements, text nodes, comment nodes, and processing instructionssomeEl.el
: an array table of child elements onlysomeEl.parent
: reference to the parent element or document tablesomeAttr.type
: the string "attribute"
someAttr.name
: the name of the attribute (without any namespace prefix)someAttr.value
: the string value of the attribute (with XML and numeric entities unescaped)someAttr.nsURI
: the namespace URI for the attribute; nil
if no namespace is appliedsomeAttr.parent
: reference to the owning element tablesomeText.type
: the string "text"
someText.name
: the string "#text"
someText.value
: the string content of the text node (with XML and numeric entities unescaped for non-CDATA elements)someText.parent
: reference to the parent element tablesomeComment.type
: the string "comment"
someComment.name
: the string "#comment"
someComment.value
: the string content of the attributesomeComment.parent
: reference to the parent element or document tablesomeComment.type
: the string "pi"
someComment.name
: the string name of the PI, e.g. <?foo …?>
has a name of "foo"
someComment.value
: the string content of the PI, i.e. everything but the namesomeComment.parent
: reference to the parent element or document tablesimple
option via:parent
attribute, elements will not have the el
collection, and the attr
collection will be a simple array (without values accessible directly via attribute name). In short, the output will be a strict hierarchy with no internal references to other tables, and all data represented in exactly one spot.foo="yes & no"
is seen as a valid attribute<foo></bar>
invokes startElement("foo")
followed by closeElement("bar")
<foo> 5 < 6 </foo>
is seen as valid text contents< > " ' &
) and numeric entities (e.g.
or <
)<?xml version="1.x"?>
) are incorrectly reported as Processing Instructionsxml
prefix is never redefined to an illegal namespacexmlns
prefix is never used as an element prefix<
). (Thanks Leorex/Ben Bishop)xml
prefix may be used without pre-declaring it. (Thanks David Durkee.)<foo xmlns="bar">
now directly generates startElement("foo","bar")
with no post callback for namespace
required.local SLAXML=require 'slaxml'
pattern to prevent any pollution of the global namespace.foo=""
closeElement
no longer includes namespace prefix in the name, includes the nsURI.parent
referencesSLAXML.ignoreWhitespace
is now :parse(xml,{stripWhitespace=true})
<foo xmlns="barURI">
will call startElement("foo",nil)
followed by namespace("barURI")
(and then attribute("xmlns","barURI",nil)
); you must apply the namespace to your element after creation.startElement("child","barURI")
<xy:foo>
will call startElement("foo","uri-for-xy")
<foo xy:bar="yay">
will call attribute("bar","yay","uri-for-xy")
"
-> "