Oracle9i XML Developer's Kits Guide - XDK Release 2 (9.2) Part Number A96621-01 |
|
This chapter contains the following sections:
The XML Parser for C++ is provided with Oracle9i and Oracle9i Application Serverand is also available for download from the OTN site: http://otn.oracle.com/tech/xml.
It is located at $ORACLE_HOME/xdk/cpp/parser
.
readme.html
in the root directory of the software archive contains release specific information including bug fixes and API additions.
XML Parser for C++ will check if an XML document is well-formed, and optionally validate it against a DTD. The parser will construct an object tree which can be accessed through a DOM interface or operate serially through a SAX interface.
You can post questions, comments, or bug reports to the XML Discussion Forum at http://otn.oracle.com/tech/xml/ .
See the following:
See Also:
|
The memory callback functions memcb
may be used if you wish to use your own memory allocation. If they are used, all of the functions should be specified.
The memory allocated for parameters passed to the SAX callbacks or for nodes and data stored with the DOM parse tree will not be freed until one of the following is done:
If threads are forked off somewhere in the midst of the init-parse-term sequence of calls, you will get unpredictable behavior and results.
Table 16-1 lists the datatypes used in XML Parser for C++.
Error message files are provided in the mesg/ subdirectory. The messages files also exist in the $ORACLE_HOME/xdk/mesg
directory. You may set the environment variable ORA_XML_MESG
to point to the absolute path of the mesg/
subdirectory although this not required.
See Also:
Available validation modes are described in "Oracle XML Parsers Validation Modes". |
Figure 16-1 illustrates the XML Parser for C++ functionality.
xmlinit()
function initializes the parsing process.DOM: If you are using the DOM interface, include the following steps:
XMLParser.xmlparse()
or .xmlparserBuffer()
method calls .getDocument Element()
. If no other DOM methods are being applied, you can invoke .xmlterm()
..xmlterm()
.xmlclean()
to clean up any data structure created during the parse process. You would then call .xmlterm()
SAX: If you are using the SAX interface, include the following steps:
.xmlclean()
to clean up the memory and structures used during a parse, and go to Step 5. or return to Step 2.xmlterm()
The sequence of calls to the parser can be any of the following:
XMLParser.xmlinit() - XMLParser.xmlparse()
or
XMLParser.xmlparsebuf() - XMLParser.xmlterm()
XMLParser.xmlinit() - XMLParser.xmlparse()
or
XMLParser.xmlparsebuf() - XMLParser.xmlclean() - XMLParser.xmlparse()
or
XMLParser.xmlparsebuf() - XMLParser.xmlclean() -... - XMLParser.xmlterm()
XMLParser.xmlinit() - XMLParser.xmlparse()
or
XMLParser.xmlparsebuf() - XMLParser.xmlparse()
or
XMLParser.xmlparsebuf() -... - XMLParser.xmlterm()
The following is the XML Parser for C++ default behavior:
Oracle XML parser for C++ checks if an XML document is well-formed, and optionally validates it against a DTD. The parser constructs an object tree which can be accessed through one of the following interfaces:
These two XML APIs:
Tree-based APIs are useful for a wide range of applications, but they often put a great strain on system resources, especially if the document is large (under very controlled circumstances, it is possible to construct the tree in a lazy fashion to avoid some of this problem). Furthermore, some applications need to build their own, different data trees, and it is very inefficient to build a tree of parse nodes, only to map it onto a new tree.
In both of these cases, an event-based API provides a simpler, lower-level access to an XML document: you can parse documents much larger than your available system memory, and you can construct your own data structures using your callback event handlers.
To use SAX, an xmlsaxcb
structure is initialized with function pointers and passed to the xmlinit()
call. A pointer to a user-defined context structure can also be included. That context pointer will be passed to each SAX function.
The SAX callback structure:
typedef struct { sword (*startDocument)(void *ctx); sword (*endDocument)(void *ctx); sword (*startElement)(void *ctx, const oratext *name, const struct xmlarray *attrs); sword (*endElement)(void *ctx, const oratext *name); sword (*characters)(void *ctx, const oratext *ch, size_t len); sword (*ignorableWhitespace)(void *ctx, const oratext *ch, size_t len); sword (*processingInstruction)(void *ctx, const oratext *target, const oratext *data); sword (*notationDecl)(void *ctx, const oratext *name, const oratext *publicId, const oratext *systemId); sword (*unparsedEntityDecl)(void *ctx, const oratext *name, const oratext *publicId, const oratext *systemId, const oratext *notationName); sword (*nsStartElement)(void *ctx, const oratext *qname, const oratext *local, const oratext *nsp, const struct xmlnodes *attrs); } xmlsaxcb;
XML Parser for C++ can be invoked in two ways:
The XML Parser for C++ can be called as an executable by invoking bin/xml
Table 16-2 lists the command line options.
XML Parser for C++ can also be invoked by writing code to use the supplied APIs. The code must be compiled using the headers in the include/ subdirectory and linked against the libraries in the lib/ subdirectory. Please see the Makefile
in the sample/ subdirectory for full details of how to build your program.
$ORACLE_HOME/xdk/cpp/parser/sample/
directory contains several XML applications to illustrate how to use the XML Parser for C++ with the DOM and SAX interfaces.
Table 16-3 lists the sample files in sample/ directory.
Change directories to the sample directory ($ORACLE_HOME/xdk/demo/cpp/parser
on SolarisTM Operating Environment) and read the README file. This will explain how to build the sample programs according to your platform.
Table 16-4 lists the programs built by the sample files in sample/.
|
Copyright © 2001, 2002 Oracle Corporation. All Rights Reserved. |
|