VTD-XML Home
|
2. How to Process XML
(Separate code-only
VTD-XML tutorials are available in
C,Java
and
C#)
Users of VTD-XML often go through the following steps to process an XML
document or message.
-
Starting with a byte
buffer: If the document resides on disk, one needs to first load the
file in memory; for an incoming SOAP message, one needs to allocate a byte
array to hold the content. Since version 1.6, one can directly use "VTDGen::parseFile()"
to parse an XML file.
-
Parsing using VTDGen:
In this step, one creates an instance of VTDGen class, then assign the byte
array to VTDGen object using "setDoc" member method. Afterwards, call
"parse" to generate VTD buffers and hierarchical info.
-
Navigation using VTDNav:
If parsing returns no error, call "getNav" of VTDGen to retrieve the VTDNav
object. The core navigation function is "toElement." It takes one of the six
pre-defined integers to determine the actual navigation action. Those
integers (self-explanatory) are: ROOT, PARENT, FIRST_CHILD, LAST_CHILD,
NEXT_SIBLING and PREV_SIBLING. To reduce the amount of typing, those six
constants also have short names: R, P, FC, LC, NS and PS. VTDNav also
contains various member methods that perform VTD to string comparison, and
convert VTD to String or numerical data. We provide a more detailed
description of VTDNav in the next subsection.
-
Node traversal using
Autopilot: This class contains member methods that emulate DOM's node
iterator. In the future, we will add XPath capabilities to it.
-
XPath evaluation using
AutoPilot: Starting from version 1.0, AutoPilot supports built-in XPath
capabilities.
-
Incremental update using
XMLModifier: Starting from version 1.8, VTD-XML introduces a new
easy-to-use XML content change class called XMLModifer.
|