Axaptapedia is now maintained by AgileCadence For more information please click here.

SaxReader class

From Axaptapedia
Jump to: navigation, search

Sax Reader[edit]

SAX stands for Simple API for XML. A Sax Parser is an event driven parser. Unlike the XMLDocument and DOM Parser it doesn't built up the complete document tree. Therefore it is faster than XMLDocument but you cannot reference nodes like in DOM.


As explained above the SAX parser is event driven. So you have to handle these events. To so create a new class that extends the SaxContentHandler class. The SaxContentHandler provides methods for handling events, like start of document, start of element node, document end, etc.

<xpp> class MySaxContentHandler extends SaxContentHandler {

  protected boolean startElement(str _namespaceURI, str _localName, str _qName, SaxAttributes _attributes)
     boolean ret;
     ret = super(_namespaceURI, _localName, _qName, _attributes);
     return ret;      

} </xpp>

Next create a new SaxReader Object and register your SaxContentHandler at the reader. The SaxReader provides two methods to start parsing: parse and parseUrl. <xpp>

SaxReader reader = new SaxReader();

reader.contentHandler(new MySaxContentHandler()); reader.parseUrl(""); </xpp>


Dynamics AX 4[edit]

Since Dynamcis AX 4 supports .NET use the System.Xml.XmlReader class to parse XML documents.