[All Packages] [Previous Class]
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 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.
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 |