MAP | SASAX Documents > What SASAX is - (2/3) [ <| 1| 2| 3| > ] |
Former section describes that (expected) structure of document to parse is (1)represented as structure of Java object and (2)examined by them in SASAX.
Then, you can examine attributes specified in element start tag by code shown in "examine attribute".
// code to parse XML document shown below. // <int attr="attr-value"> // 123456 // </int> IntElement element = new IntElement(null, "", "int"){ protected void examine(ParseContext context, Attributes attrs) throws SAXException // { String value = attrs.getValue("", "attr"); // examine value of attr } };
Of course, you can examine attributes of "composite" element in same manner. Please see API document for detail.
SASAX also provides extensible value examination mechanism to customize XML document examination procedure.
You can examine value of element itself by code shown in "examine value".
IntElement element = new IntElement(null, "", "int"); element.addValidation(new Validation(){ public Object validate(ParseContext context, Object value) throws SAXException // { Integer integer = (Integer)(value); switch(integer.intValue()){ case 128: case 512: case 4096: return value; default: throw new SAXNotRecognizedException("invalid"); } } });
At first,
IntElement
examines whether the value specified(as string) in XML document is
acceptable one as string representation of integer.
Then it passes deserialized, as java.lang.Integer
,
value to your custom Validation
.
So,
the inner class in above example,
which implements Validation
,
can examines "value" specified in XML document as "Integer"
You can customize examination procedure
by combination of multiple Validation
s,
and re-use your custom Validation
.
MAP | SASAX Documents > What SASAX is - (2/3) [ <| 1| 2| 3| > ] |