Prev | Current Page 848 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

??? is not allowed in attribute name
< person name=???John D.??? sex=???m???/ >
// fails because ???x??? is not in the list of the acceptable values for sex
< person name=???John Doe??? sex=???x???/ >
As already mentioned, the filters can also be applied to Character Data contents. In the following
example, the rule applies to an element node with the name person that has an attribute name , and has
two subnodes age and male that must contain respectively a textual node that represents an integer
number and a value that can be converted to a Boolean value.
var schema = RNode(???person???,
[Att(???name???, FReg(~/^.{3,20}$/))], // any string of 3 to 20 characters
RList([
RNode(???age???, RData(FInt)),
RNode(???male???, RData(FBool)),
], true));
Chapter 16: haXe Advanced Topics
463
See how the following XML fragments behave when validated against the preceding rule:
// passes the validation
< person name=???John Doe??? > < age > 35 < /age > < male > true < /male > < /person >
// passes, too
< person name=???John Doe??? > < age > -1 < /age > < male > 1 < /male > < /person >
// fails because age is not numeric
< person name=???John Doe??? > < age > x < /age > < male > true < /male > < /person >
// fails because male has wrong casing
< person name=???John Doe??? > < age > 35 < /age > < male > True < /male > < /person >
Check is certainly a useful tool that is probably still underestimated in the haXe community.


Pages:
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860