MAP | SASAX Documents > What SASAX is - (3/3) [ <| 1| 2| 3| > ] |
You may want to create specific Java object from value(s) specified in XML document. SASAX provides the way to notify determination of element value (or component values) for that requirement.
For example,
code to create
user specific container "CompositeContainer
"
from "composite
"(and its components) in XML document
is shown in "notification receiving".
// <composite> // <int>123456</int> // <string>string value</string> // </composite> public class Composite extends CompositeElement { final private IntElement int_ = new IntElement(this, "", "int"); final private StrignElement string_ = new StringElement(this, "", "string"); //////////////////////////////////////// public Composite(Element parent){ super(parent, "", "composite"); addMustItem(int_); addMustItem(string_); } //////////////////////////////////////// // Overriding of class CompositeElement protected void notifyDetermined() throws SAXException // { Integer integer = int_.getInteger(false); String string = string_.getString(false); CompositeContainer value = new CompositeContainer(integer, string); // e.g.: store value into somewhere else } }
As shown above,
you can receive notification of determination of value(s)
by overriding of "notifyDetermined()
" method.
As described in "Poorness around namespace", SAX API has complexity around identification of element/attribute name because it depends on namespace awareness of XML parser for own one.
SASAX provides adaptation class to provide pseudo namespace awareness for namespace non-aware SAXParser. Example to parse with namesapce non-aware SAXParser is shown as "namespace awareness support".
// "adaptee" is derived class of DefaultHandler PrefixMappingAdapter adapter = new PrefixMappingAdapter(adaptee); SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); parser.parse(inputSource, adapter);
In above example,
"adaptee
" can receive "namespace URI" and "local name"
on "startElement()
" and "endElement()
" events,
and you can look attributes up by
"namespace URI" and "local name" on "startElement()
",
even if (default) SAXParser have no namespace awareness.
So, SASAX can define API which only treats "namespace URI" and "local name" because it can assume namespace awared environment as described above, and you can write handling logic easily.
In addtion to it, SASAX provides functionality to look mapping up between "namespace URI prefix" and "namespace URI". You can examine prefixed value of element/attribute by it easily.
MAP | SASAX Documents > What SASAX is - (3/3) [ <| 1| 2| 3| > ] |