JDOM_Document methods

 

JDOM_Document methods

 

Figure 25. The JDOM_Document metaclass

 

The following methods are provided by the JDOM_Document metaclass:

getDocumentElement () : JDOM_Node;

This returns a reference to the XML document root element.

 

getDoctype() : JDOM_Node;

This returns the Doctype of the XML document, or null if this is not present.

 

getElementsByTagName(In pTagName : String,

                Inout pElts [*] JDOM_Node);

This returns elements named pTagName which are contained in the XML document in the pElts list.

 

Note:      For optimization reasons, the set is not returned but is instead passed as the InOut parameter.  In this respect, this method differs from the standard DOM API.

 

Unlike the DOM API, the returned list is not dynamic, but is rather a copy of the tree at a given moment in time.

 

createElement (In pName : String) : JDOM_Element;

This creates an element named pName.

 

createTextNode (In pData : String) : JDOM_Node;

This creates a text using the pData data.

 

createComment (In pData : String) : JDOM_Node;

This creates a comment using the pData data.

 

createCDATASection (In pData : String) : JDOM_Node;

This creates a CDATASection using the pData data.

 

createProcessingInstruction  (In pTarget : String,

                               In pData : String):

                               JDOM_Node;

This creates a "Processing Instruction" using the desired information.

 

createAttribute (In pName : String) : JDOM_Node;

This creates an attribute named pName.

 

createXMLDocument () : JDOM_Document;

This creates a new empty document (this replaces createDocument () of the DOM API).

 

createXMLDocumentSkeleton (In pNamespaceURI : String,

                      In  pQualifiedName : String,

                           In pPublicId : String,

                          In pSystemId : String) :

                          JDOM_Document;

This creates a document skeleton containing a DocumentType node, as well as an empty root element.

 

createDocumentType (In pName : String,

                      In pPublicId : String,

                      In pSystemId : String):

                 JDOM_Node;

This creates a DocumentType node.

 

createEntityReference (In pName : String) : JDOM_Node;

This creates an entity reference named pName.

 

createXMLDecl(In pVersion:String,

            In pEncoding:String,

                 In pStandAlone:String) :JDOM_Node;

This creates an XML declaration with the transmitted data.

 

importNode(Inout pNodeToImport: JDOM_Node,

        In pDeep : JDOM_Node):JDOM_Node;

This method should be used instead of the cloneNode method, available on JDOM_Node.

The import runs a duplication of the node and attaches it to the method's application document.  pDeep indicates that you wish to copy all the sub-elements of the node which is to be imported.

 

For example:      

 

lElement = lDoc.createElement("AnElement") ;

lElement2= lDoc2.importNode(lElement,true);

//Copying the element named "AnElement" with its

sub-elements and affecting it to lElement2

lDoc2.getDocumentElement().appendChild(lElement2) ;

//Attaching the copy to the "root" element of the

lDoc2 document.

 

 

printXML (In pXMLFilePath : String) : Boolean;

This saves the XML file, giving it the complete path of the XML file.

 

+getElementById(In elementId :string) :JDOM_Element

This method returns the DOM_Element whose ID is given by the elementId parameter.  If no such element exists, it returns null.  Behavior is not defined if more than one element has this ID.