User Guide > Using the XML Toolkit > Using the PV-WAVE XML Toolkit
  

Using the PV-WAVE XML Toolkit
There are two methods used to parse XML documents, DOM parsers and SAX parsers. DOM (Document Object Model) parsers read an entire XML document and create a memory model of this document that can be queried and manipulated. All but one routine, SaxInit, in the PV‑WAVE XML Toolkit are used for DOM parsing and manipulation. SAX parsers offer an event driven approach to parsing a document. Both of these methods and the PV‑WAVE XML Toolkit routines used are described below.
DOM Parser
The DOM parser builds a memory model of an entire XML document that can be queried and manipulated in powerful ways. The XmlParse routine performs this function and creates a “handle” to the DOM object which is used by other routines. Typically after parsing the document you would use the XmlEvaluate routine to perform a query on the document and return “nodes” of interest. Each node is essentially a tag in XML which can contain content and attributes.
In many applications that read XML this is probably all you would need to do. If you wanted to modify the contents of the document and pass it on to another application you could use routines like XmlSetContent and XmlSetAttr. You can also add new nodes with XmlNewNode and XmlAddNode. Finally, you can write out the internal DOM representation to an XML document with XmlDocDump.
In some cases you may need to generate an XML document entirely from scratch. You can use XmlNewDoc, XmlNewNode, XmlSetAttr and XmlAddNode, along with XmlDocDump to accomplish this.
SAX Parser
The second method of parsing XML documents is the SAX (Simple API for XML) parser. The single routine SAXInit is used for this. The SAX parser simply reads the XML file and calls a user specified callback function for each element it finds in the XML document. There are a number of events defined which cause the callback routine to be executed and you can filter out which of these events you are interested in.
With the SAX parser you can not do sophisticated queries on the XML document, but it is an easy way to filter a large document and pull out just particular items of interest. You can not modify or manipulate the XML document as you can with a DOM model, but simply get the contents and attributes of interest in the order that they appear in the document.
Because the PV‑WAVE XML Toolkit offers low level access to most of the functionality of the underlying parser, there are few limitations in the kinds of applications you can find for XML and PV‑WAVE.

Version 2017.1
Copyright © 2019, Rogue Wave Software, Inc. All Rights Reserved.