[All Packages]  [Previous Class]

Class: generated

All generated classes are enclosed in a C++ namespace with the same name as the generated files (i.e. Foo.cpp will contain namespace Foo).

A generated class is produced for each element in the Schema. It has the same name as the element, except for local elements which have the parent element's name prefixed.

If an element (or attribute) name cannot be used directly as a C++ identifier, it is mapped to a valid identifier by converting it to the compiler character set (ASCII or EBCDIC) and then replacing unmappable characters with the two-letter hex for their code points. For example, the element name "Curaçao" maps to "Curacao", but "kþorn" maps to "kFEorn". If the remapped name is already used, digits are appended to the end to make it unique ("Curacao0", etc).

Note that elements and attributes created by the generated classes will have the original names. The remapping only applies to the generated code itself (so that it will be syntactically correct C++), not to the XML elements and data which are constructed by them.

Constructors are provided which create an empty element, or to 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, assuming C++ namespace Queue, and given the element declaration

the following constructors will be provided: The first constructor just makes an empty element with no children. The second initializes it with PCDATA (since the element's type content is mixed), and the third with a single child node of element thing. An element like foo which may contain PCDATA is also given a method to add the data post-construction:

Each possible child element of foo also is given an "assembler", like so: The following usages are equivalent:

and Similarly, the following are also equivalent:

and Not all possible combinations of initial elements are provided constructors, especially considering variable occurances. If no constructor fits the bill, you must build up the element assembly-style. For example, given the element definition A map_data element may contain any number of aq:item children. In such a case, a constructor is provided which allows on one occurance; additional occurances must be assembled in, like the following example which needs four: See the sample program AQ.cpp (in the samples/ directory) for a complete example. For each attribute for an element, a method is provided to set its value, named set_attrname. For example, for the element declaration

a method would be provided to set the attribute: Note: The constructed element is not tested for validity as it is being made. The user to explicitly call the XMLSchema'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
set_attribute Sets one of the element's attributes

Methods

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 the_node)

Arguments:
the node -- node to be added

Returns:
none

set_attribute

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

Prototype:
Attr* set_attribute(String value)

Arguments:
value -- the attribute's value

Returns:
Attr* -- the created attribute