Prev | Current Page 838 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

node.writer.node.name.innerData);
else
trace(???No writers!???);
Accessing Attributes
Retrieving attributes is even easier than accessing elements. You can use has to check if an attribute
exists and att to get its value.
class Main
{
public static function main()
{
var doc = Xml.parse(Std.resource(???sample???));
var fdoc = new haxe.xml.Fast(doc);
var people = fdoc.node.people;
for(n in people.nodes.person)
{
var name = n.node.name.innerData;
var sex = if(!n.has.sex)
???unknown???
else if(n.att.sex == ???m??™)
???male???
else
???female???;
trace(name + ???, ??? + sex);
}
}
}
Part III: Extending the Possibilities
458
When you access nodes and attributes in this way, it is very easy and fast (no pun intended). Nodes and
attributes are blended in a seamless way in the code flow.
Check
Sometimes a well - formed document is not enough. Before processing a document you must be sure that
it is built conforming to some rules. This kind of validation is traditionally performed using DTD or an
XML Schema document.


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