Prev | Current Page 837 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

xml.Fast(doc);
var people = fdoc.node.people;
for(n in people.elements)
trace(???person name: ??? + n.node.name.innerData + ??? [??? + n.name + ???]???);
// same collection as before but the node of William Shakespeare
// is left behind because it is not an element with name person
for(n in people.nodes.person)
trace(???person name: ??? + n.node.name.innerData);
trace(???author name: ??? + people.node.author.node.name.innerData);
}
}
The innerData is a handy shortcut to access the textual content ( PCData or CData ) of the current
element. If the node contains other elements or more than one node, an error is thrown. The name
variable contains the name of the current element; this value is only available if the node is of the
Element type (not Document ).
As querying a node for elements with the wrong name raises an exception, you can check the existence
of a certain element using the hasNode operator. Remember that the described operators are just plain
instance fields.
if(people.hasNode.writer)
trace(???writer name: ??? + people.


Pages:
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849