The DOMDocument object represents an XML document.
The DOMDocument object inherits properties and methods from the DOMNode object.
The DOMDocument object represents the root of the DOM document node tree, and provides the primary access to the document's data.
Constructors
[new] DOMDocument(string) |
Constructs and returns a new DOMDocument object instance. |
[new] DOMDocument.parseFile(path) |
Constructs and returns a new DOMDocument object instance. The path parameter is a string indicating the path of the file to parse, e.g. "AddressBook/default.view"; |
[new] DOMDocument.parseResponse(resp) |
Constructs and returns a new DOMDocument object instance. The parameter resp is a HTTPResponse object instance. | |
Instance Properties
doctype |
Returns a DOMDocumentType object instance. |
implementation |
Returns a DOMImplementation object instance. |
documentElement |
The value of this property is the root element of the DOMDocument object. | |
Instance Methods
Examples
The following examples demonstrate the constructors for the DOMDocument object.
Example #1
var doc = null;
doc = DOMDocument("<person><name>Mark</name>
<email>mark@address.com</email></person>");
Example #2
var doc = null;
doc = DOMDocument.parseFile("/AddressBook/AddressBook.view");
Example #3var ua = new HttpUserAgent();
var resp = ua.Request(http://www.google.com);
var doc = new DOMDocument.parseResponse(resp);
Examples #4
The following example demonstrates the documentElement property of the DOMDoc object. It also shows how DOMDoc objects inherit the properties and methods of the DOMNode objet.
var str = '<table border="1" cellspacing="o" cellpadding="0"
colspan="2"><tr><td>cell1</td><td>cell2</td></tr>
<tr><td>cell3</td><td>cell4</td></tr></table>';
//doc is a DOMDoc object representing a table with four cells
var doc = new DOMDocument(str);
response.write("doc.documentElement: ",
doc.documentElement, "<br>");
response.write("doc.documentElement.nodeName: ",
doc.documentElement.nodeName, "<br>");
response.write("doc.documentElement.childNodes
.item(0).nodeName: ",
doc.documentElement.childNodes
.item(0).nodeName, "<br>");
Output:
doc.documentElement:
doc.documentElement.nodeName: table
doc.documentElement.childNodes.item(0).nodeName: tr