Using XMLC Generated Objects

Generated XMLC Objects are manipulated using the DOM API as well as element access methods generated by XMLC. Dynamic data is set in the DOM object tree and finally an HTML page is generated from that tree.

Generated Document Class

The xmlc command compiles the document into a Java class with the following attributes:

Element Access Methods

In addition to the standard DOM document access method, the generated class will contain a get method for each element that contains an identifier attribute.

For HTML documents, this is the id attribute, valid for almost all tags. With XML documents, these are all attributes declared to be type ID in the DTD.

The get method will be named in the form getElementIdname. With the first character of the id being shifted to upper case to conform to the Java convention. The return type will be the DOM class that represents the element. For an element:

   <INPUT ID="nameInput">
The method:
   HTMLInputElement getElementNameInput();
is generated.

Element ids that can not be converted to a legal Java identifiers will not have access methods generated for them.

Name and Class Constants

String constants will be generated for each element name and class name. The use of string constants when calling DOM routines to locate elements. ensures that a valid element is specified.

For an element:

   <INPUT NAME="myName"> CLASS="class1 class2">
The constants
   public static final String NAME_myName;
   public static final String CLASS_class1;
   public static final String CLASS_class2;

Despite the fact that the HTML specification defines NAME attributes as case-insensitive, HTTP servers treat the name as case-sensitive. To support element names that vary only by case, the case of the name is not modified when generating the field name. Class names are case-sensitive, so their case is not modified. Element names and classes that can not be converted to a legal Java identifiers will not have access methods generated for them.

These constants are used when accessing the DOM, for example:

    NodeList elements = htmlObj.getElementsByName(htmlObj.NAME_myName);

Embedding unparsed HTML

In many applications, text containing HTML is available from external sources, such as database or user input. It maybe impractical to parse these HTML document fragments into a DOM hierarchy. The XMLC HTML formatter provides a non-standard extension for including unparsed HTML. CDATASection nodes will have their data inserted unchanged into the HTML document created with by the toDocument() method.

Warning: The DOM specification makes no allowances for including unparsed HTML and this is not one of their goals. The DOM is intended object representation of the document that is independent of file syntax. The use of CDATASection is non-standard and should be used with care. Other DOM-based tools that you might wish to use with XMLC-generated object will probably not support this functionality. In general, creating a document as a DOM hierarchy of elements is a safer and more extensible approach. This functionality will not be support for XML documents.