Prev | Current Page 840 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

parse(xml);
var schema = RNode(???root???);
try
{
Check.checkDocument(doc, schema);
} catch(e : String) {
trace(???Validation failed: ??? + e);
}
}
}
Do not forget to import the haxe.xml.Check class because the rules for the validation check are defined
in there. In this case only an RNode has been applied and the document is checked using the
checkDocument() function. The function is invoked inside a try block because in case of failure an
exception is raised.
All the string comparisons in the Check API are case sensitive; this is particularly important when
defining rules for elements and attributes.
Checking Nodes
The nodes are checked using the enum Rule . Rule has several constructors to cover many possible
validation conditions.
Chapter 16: haXe Advanced Topics
459
RN ode
The RNode constructor acts on a single node whose element name must match the first argument. The
second optional argument is an array of attribute validation rules. If omitted or empty, the node must
not have attributes to be valid.


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