Home

News

International

Screen Shots

Documentation

Download

Build

License

Credits

Contact

SourceForge Project

Tintware Documentation : Tint Programming Language : Tint Reference : XML : xml-tree

XML tree structure

This page will attempt to explain how an XML document gets mapped into the Tint namespace using xml.tree. An XML document and the Tint namespace are both hierarchical structures. Each element in an XML document is a node in the Tint namespace. Children of an element (elements, data, and attributes) are accessed using at dot (.) and then a reference to a child. References can take different forms depending upon what you are looking for.

The root element of the XML document is referenced via the first argument that was specified to xml.tree. The values of attributes are referenced using the name of the attribute prefixed by a $. The first subtag of a list of children can be referenced by name.

#(xml.tree,a-tree,(<tag a1="v1"><t1 a1="sv1" /><t2 a2="v2" /></tag>))

#(a-tree.$a1)
v1
#(a-tree.t1.$a1)
sv1
#(a-tree.t2.$a2)
v2

Each element contains an ordered list of children (elements and data). This list can be accessed like an array in several ways. It can be treated as an array of everything -- both data and elements.

#(xml.tree,a-tree,(<tag>aa<t1>text</t1>bb<t1>other</t1>cc<t2>stuff</t2>dd</tag>))

#(tint.type,a-tree.{1})
data
#(a-tree.{1})
aa
#(tint.type,a-tree.{2})
element
#(a-tree.{2})

#(a-tree.{2}.{1})
text
#(tint.type,a-tree.{6})
element
#(a-tree.{6}.{1})
stuff

It can be treated as an array of data, ignoring any elements.

#(xml.tree,a-tree,(<tag>aa<t1>text</t1>bb<t1>other</t1>cc<t2>stuff</t2>dd</tag>))

#(a-tree."1")
aa
#(a-tree."2")
bb
#(a-tree."3")
cc
#(a-tree."4")
dd
#(def?,a-tree."4",y,n)
y
#(def?,a-tree."5",y,n)
n

It can be treated as an array of elements, ignoring any data. This can be done several ways. The first way is an array of all the elements. Nodes which are elements can be queried as to their tag and namespace using @tag and @namespace.

#(xml.tree,a-tree,(<tag>aa<t1>text</t1>bb<t1>other</t1>cc<t2>stuff</t2>dd</tag>))

#(a-tree.[1].@tag)
t1
#(a-tree.[1]."1")
text
#(a-tree.[1].@namespace)

#(a-tree.[2].@tag)
t1
#(a-tree.[2]."1")
other
#(a-tree.[3].@tag)
t2
#(def?,a-tree.[3],y,n)
y
#(def?,a-tree.[4],y,n)
n
#(xml.tree,a-tree,(<tag xmlns="example"><t1></t1></tag>))

#(a-tree.[1].@tag)
t1
#(a-tree.@namespace)
example
#(a-tree.[1].@namespace)
example

The second way to access elements is an array of all of the elements with a given tag.

#(xml.tree,a-tree,(<tag><t1>text</t1><t2>other</t2><t1>stuff</t1></tag>))

#(a-tree.t1[1]."1")
text
#(a-tree.t1[2]."1")
stuff
#(def?,a-tree.t1[2],y,n)
y
#(def?,a-tree.t1[3],y,n)
n

The final way to access elements is an array of all of the elements with a given tag and namespace.

#(xml.tree,a-tree,(<tag xmlns="aaa" xmlns:b="bbb"><t1>11</t1><b:t1>22</b:t1></tag>))

#(a-tree.<bbb>t1[1]."1")
22
#(a-tree.<aaa>t1[1]."1")
11

Finally, an element and all of its decendants can be converted into text using @to-text.

#(xml.tree,a-tree,(<tag><t1>text</t1><t2>other</t2><t1>stuff</t1></tag>))

#(a-tree.[2].@to-text)
<t2>other</t2>
#(a-tree.@to-text)
<tag><t1>text</t1><t2>other</t2><t1>stuff</t1></tag>