Skip Headers

Oracle9i XML Reference
Release 1 (9.0.1)

Part Number A88899-01
Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Go to previous page Go to next page

10
Oracle XML Class Generator (C++)

This chapter details the XML Class Generator for C++ and how it defines each element. It contains:

Overview of the XML Class Generator for C++

The XML Class Generator takes a Document Type Definition (DTD) and generates classes for each defined element. Those classes are then used in a C++ program to construct XML documents conforming to the DTD. Supported operating systems are Solaris 2.6, Linux 2.2, and NT 4 (Service Pack 3 and above).


Input

Input is an XML document containing a DTD. The document body itself is ignored; only the DTD is relevant, though the dummy document must conform to the DTD. The underlying XML parser only accepts file names for the document and associated external entities. In future releases, no dummy document will be required, and URIs for additional protocols will be accepted.

The following input file encodings are supported:

UTF-8, UTF-16, US-ASCII, ISO-10646-UCS-2, ISO-8859-1, ISO-8859-2, ISO-8859-3, ISO-8859-4, ISO-8859-5, ISO-8859-6, ISO-8859-7, ISO-8859-8, ISO-8859-9, EUC-JP, SHIFT_JIS, BIG5, GB2312, KOI8-R, EBCDIC-CP-US, EBCDIC-CP-CA, EBCDIC-CP-NL, EBCDIC-CP-WT, EBCDIC-CP-DK, EBCDIC-CP-NO, EBCDIC-CP-FI, EBCDIC-CP-SE, EBCDIC-CP-IT, EBCDIC-CP-ES, EBCDIC-CP-GB, EBCDIC-CP-FR, EBCDIC-CP-HE, EBCDIC-CP-BE, EBCDIC-CP-CH, EBCDIC-CP-ROECE, EBCDIC-CP-YU, and EBCDIC-CP-IS.

In addition, any character set specified in Appendix A, Character Sets, of the Oracle National Language Support Guide may be used. The default encoding is UTF-8. It is recommended that you set the default encoding explicitly if using only single byte character sets (such as US-ASCII or any of the ISO-8859 character sets) for performance up to 25% faster than with multibyte character sets such as UTF-8.


Output

Output is a pair of C++ source files, .cpp and .h, named after the DTD. Constructors are provided for each class (element) that allow an object to be created in two different ways: initially empty, then adding the children or data after the initial creation, or created with the initial full set of children or initial data. A method is provided for #PCDATA (and Mixed) elements to set the data and, when appropriate, set an element's attributes.


Relevant XML Standards

The W3C recommendation for Extensible Markup Language (XML) 1.0

The W3C recommendation for Document Object Model Level 1 1.0

The W3C proposed recommendation for Namespaces in XML

The Simple API for XML (SAX) 1.0


sample/Example usage

xmlcg Usage

The standalone parser may be called as an executable by invoking

bin/xmlcg like
xmlcg [flags] <XML document>

where the optional flags are as follows:

-d
directory
Specify output directory (default 	is current directory)

-e

encoding

Specify default input file encoding

-h help

show this usage help


Class: XMLClassGenerator

This class contain the method for generating classes based on a DTD.

METHOD INDEX

generate 

Generate classes 

METHODS

generate

Function:

Generates classes for the given DTD. Two files are created in the output directory outdir (or in the currect directory if outdir is NULL): DTDname.h and DTDname.cpp, both named after the DTD. One class is generated for each defined element in the DTD.

Prototype:

uword generate(DocumentType *dtd, char *outdir)

Arguments:

dtd -- DTD whose elements to generate classes for

outdir -- directory in which to place output files

Returns:

uword -- error code, 0 on success


Class: generated

A generated class is produced for each element defined in the DTD. It has the same name as the element.

Constructors are provided which create an empty element, or make it with an initial set of children or data. Methods are provided to add children or data after construction, and to set attributes. There are two styles of creation: make an empty element, then add the children one at a time, or construct the element with initial data or children. For example, given the element declaration

<!ELEMENT B (#PCDATA | F)*>

The following constructors will be provided:

B(Document *doc);

B(Document *doc, String data);

B(Document *doc, F *theF);

The first constructor just makes an empty element with no children. The second initializes it with PCDATA, and the third with a single child node of element F. An element like B which may contain PCDATA is also given a method to add the data post-construction:

void addData(Document *doc, String data);

The following usages are equivalent:

b = new B("data");

and

b = new B();

b->addData("data");

Similarly, the following are also equivalent:

f = new F(...);

b = new B(f);

and

f = new F(...);

b = new B();

b->addNode(f);

The presense of modifiers '?' (optional), '*' (zero or more), and '+' (one or more) is ignored when forming the constructors. For example, for the element

<!ELEMENT Sample (A* | (B, (C? | (D, E)*)) | F)+>

the following constructors are made:

Sample(Document *doc);

Sample(Document *doc, A *theA);

Sample(Document *doc, B *theB, C *theC);

Sample(Document *doc, B *theB, D *theD, E *theE);

Sample(Document *doc, F *theF);

as if the modifiers were not present. If you cannot make the desired final element using one of the forms which take initial children, you must start with the empty element and add nodes as needed with addNode as above.

For each attribute for an element, a method is provided to set its value, named setattrname. For example, for the element declaration

<!ELEMENT D (#PCDATA)>
<!ATTLIST D foo CDATA #REQUIRED>

the class D will have the method

Attr* setfoo(String value);

Note: The constructed element is not tested for validity as it is being made. The user to explicitly call the XMLParser's validate method on the final element.

METHOD INDEX

Constructors

Constructors for the class

addData 

Adds PCDATA to the element 

addNode 

Adds a node to the element 

setattribute 

Sets one of the element's attributes 

METHOD

Constructors

Function:

Constructs an element which will belong to the given document. The first form makes the element with no children (use addData and addNode as appropriate to fill it out). The second variable form is used to provide initial data or children, the exact choices of which depend on the element definition. See the example at the beginning of this document.

Prototype:

class(Document *doc) 
class(Document *doc, ...)

Arguments:

doc -- document which the element belongs to

... -- varying arguments depending on the element definition

Returns:

none

addData

Function:

Adds data to the element. That is, appends to it a PCDATA subnode with the given value. If multiple addData calls are made, the node will have multiple PCDATA subnodes, which should be normalized when construction is finished.

Prototype:

void addData(Document *doc, String data)

Arguments:

doc -- document which the element belongs to

data -- data to be added

Returns:

none

addNode

Function:

Adds (append) a child node to the element. No effort is made to validate the resulting element structure at this time; it is the user's responsibility to form the element properly, which may be verified with XMLParser::validate.

Prototype:

void addNode(node thenode)

Arguments:

the node -- node to be added

Returns:

none

setattribute

Function:

Sets the element's attribute with the given value. One method is provided for each attribute, named after the attribute as setattribute.

Prototype:

Attr* setattribute(String value)

Arguments:

value -- the attribute's value

Returns:

Attr* -- the created attribute


Go to previous page Go to next page
Oracle
Copyright © 1996-2001, Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index