Home of: [Atelier "FUJIGURUMA"] >> [SASAX hosted by SourceForge.net]

SEE "For Readers of English Version",
or Japanese version of this page

What SASAX is - (2/3)

Examination of values

Examination of attribute

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
        }
    };

examine attribute

Of course, you can examine attributes of "composite" element in same manner. Please see API document for detail.

Examination of value

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");
        }
    }
});
examine value

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 Validations, and re-use your custom Validation.


>> Next page(3/3), or jump from navigator bar at the top/bottom of page