Overview
The Document
interface represents the entire HTML or XML
document. Conceptually, it is the root of the document tree, and provides
the primary access to the document's data.
Since elements, text nodes, comments, processing instructions, etc.
cannot exist outside the context of a Document
, the
Document
interface also contains the factory methods needed
to create these objects. The Node
objects created have a
ownerDocument
attribute which associates them with the
Document
within whose context they were created.
See also the Document Object Model (DOM) Level 3 Core Specification.
Attribute Summary
name | type | description |
---|---|---|
Public | ||
document | Document |
holds the internal org.w3c.dom.Document |
documentElement | Element |
holds the document element |
doIndent | Boolean |
indicates whether or not indenting should be used when printing or serializing. |
encoding | String |
indicates which encoding should be used when printing or serializing. |
indent | Integer |
Holds the number of spaces for indenting when printing or serializing. |
namespace | NamespaceContext |
Holds an optional namespace context used for serializing or printing the document |
omitXMLDeclaration | Boolean |
indicates whether or not to include the xml declaration when printing or serializing. |
standalone | Boolean |
indicates whether or not the document is standalone. |
Protected |
Inherited Attributes
Function Summary
- public createAttribute(name: String, value: String, ) : Attribute
-
Creates an
Attr
of the given name. - public createAttributeNS(namespaceURI: String, qualifiedName: String, value: String, ) : Attribute
-
Creates an attribute of the given qualified name and namespace URI.
- public createCDATASection(cdata: String, ) : Node
-
Creates a
CDATASection
node whose value is the specified string. - public createComment(comment: String, ) : Comment
-
Creates a
Comment
node given the specified string. - public createElement(tagName: String, ) : Element
-
Creates an element of the type specified.
- public createElementNS(namespaceURI: String, qualifiedName: String, ) : Element
-
Creates an element of the given qualified name and namespace URI.
- public createEntityReference(name: String, ) : Node
-
Creates an
EntityReference
object. - public createProcessingInstruction(target: String, data: String, ) : Node
-
Creates a
ProcessingInstruction
node - public createText(data: String, ) : Text
-
Creates a
Text
node given the specified string. - public getElementById(elementId: String, ) : Element
-
Returns the
Element
that has an ID attribute with the given value. - public getElementsByTagName(tagName: String, ) : <any>[]
-
Returns a sequence of all the
Elements
in document order with a given tag name and are contained in the document. - public getElementsByTagNameNS(namespaceURI: String, localName: String, ) : <any>[]
-
Returns a sequence of all the
Elements
with a given local name and namespace URI in document order. - public query(query: String, ) : <any>[]
-
Perform an xpath query on the document
- public queryBoolean(query: String, ) : Boolean
-
Perform an xpath query on the document expecting a Boolean result
- public queryNode(query: String, ) : Node
-
Perform an xpath query on the document expecting a Node result
- public queryNumber(query: String, ) : Number
-
Perform an xpath query on the document expecting a Number result
- public queryString(query: String, ) : String
-
Perform an xpath query on the document expecting a String result
- public serialize(writer: Writer, ) : Void
-
Convert the document to an XML format based on the attributes indent, doIndent, omitXMLDeclaration, encoding and standalone.
- public toString() : String
-
Convert the document to an XML formatted string based on the attributes indent, doIndent, omitXMLDeclaration, encoding and standalone.
Inherited Functions
Attributes
public document: Document
holds the internal org.w3c.dom.Document
public documentElement: Element
holds the document element
public doIndent: Boolean
indicates whether or not indenting should be used when printing or serializing. Default is true
public encoding: String
indicates which encoding should be used when printing or serializing. Default is null, use system default.
public indent: Integer
Holds the number of spaces for indenting when printing or serializing. doIndent must be true for this to take effect. Default indent is 2.
public namespace: NamespaceContext
Holds an optional namespace context used for serializing or printing the document
public omitXMLDeclaration: Boolean
indicates whether or not to include the xml declaration when printing or serializing. Default is false (xml declaration is included).
public standalone: Boolean
indicates whether or not the document is standalone. Default is false
Functions
public createAttribute(name: String, value: String, ):Attribute
-
Parameters
- name
- The name of the attribute.
- value
-
Returns
- Attribute
- A new <code>Attr</code> node.
Creates an Attr
of the given name.
public createAttributeNS(namespaceURI: String, qualifiedName: String, value: String, ):Attribute
-
Parameters
- namespaceURI
- The namespace URI of the attribute to create.
- qualifiedName
- The qualified name of the attribute to instantiate.
- value
-
Returns
- Attribute
- A new <code>Attr</code> node.
Creates an attribute of the given qualified name and namespace URI.
public createCDATASection(cdata: String, ):Node
-
Parameters
- cdata
- The data for the <code>CDATASection</code> contents.
-
Returns
- Node
- The new <code>CDATASection</code> node.
Creates a CDATASection
node whose value is the specified
string.
public createComment(comment: String, ):Comment
-
Parameters
- comment
- The comment data for the node.
-
Returns
- Comment
- The new <code>Comment</code> node.
Creates a Comment
node given the specified string.
public createElement(tagName: String, ):Element
-
Parameters
- tagName
- The name of the element type to instantiate
-
Returns
- Element
- A new <code>Element</code>.
Creates an element of the type specified.
public createElementNS(namespaceURI: String, qualifiedName: String, ):Element
-
Parameters
- namespaceURI
- The namespace URI of the element to create.
- qualifiedName
- The qualified name of the element type to instantiate.
-
Returns
- Element
- A new <code>Element</code>
Creates an element of the given qualified name and namespace URI.
public createEntityReference(name: String, ):Node
-
Parameters
- name
- The name of the entity to reference.
-
Returns
- Node
- The new <code>EntityReference</code> node.
Creates an EntityReference
object.
public createProcessingInstruction(target: String, data: String, ):Node
-
Parameters
- target
- The target part of the processing instruction.
- data
- The data for the node.
-
Returns
- Node
- The new <code>ProcessingInstruction</code> node.
Creates a ProcessingInstruction
node
public createText(data: String, ):Text
-
Parameters
- data
- The data for the node.
-
Returns
- Text
- The new <code>Text</code> node.
Creates a Text
node given the specified string.
public getElementById(elementId: String, ):Element
-
Parameters
- elementId
- The unique <code>id</code> value for an element.
-
Returns
- Element
- The matching element or <code>null</code> if there is none.
Returns the Element
that has an ID attribute with the
given value. If no such element exists, this returns null
. If more than one element has an ID attribute with that value, what
is returned is undefined.
public getElementsByTagName(tagName: String, ):<any>[]
-
Parameters
- tagName
- The name of the tag to match on. The special value "*" matches all tags. For XML, the <code>tagname</code> parameter is case-sensitive, otherwise it depends on the case-sensitivity of the markup language in use.
-
Returns
- <any>[]
- A new sequence containing all the matched <code>Elements</code>.
Returns a sequence of all the Elements
in
document order with a given tag name and are contained in the
document.
public getElementsByTagNameNS(namespaceURI: String, localName: String, ):<any>[]
-
Parameters
- namespaceURI
- The namespace URI of the elements to match on. The special value <code>"*"</code> matches all namespaces.
- localName
- The local name of the elements to match on. The special value "*" matches all local names.
-
Returns
- <any>[]
- A new sequence containing all the matched <code>Elements</code>.
Returns a sequence of all the Elements
with a
given local name and namespace URI in document order.
public query(query: String, ):<any>[]
-
Parameters
- query
- the xpath query
-
Returns
- <any>[]
- a sequence of Nodes that match the query
Perform an xpath query on the document
public queryBoolean(query: String, ):Boolean
-
Parameters
- query
- the xpath query
-
Returns
- Boolean
- a boolean value representing the result of the query
Perform an xpath query on the document expecting a Boolean result
public queryNode(query: String, ):Node
-
Parameters
- query
- the xpath query
-
Returns
- Node
- a Node representing the result of the query
Perform an xpath query on the document expecting a Node result
public queryNumber(query: String, ):Number
-
Parameters
- query
- the xpath query
-
Returns
- Number
- a number value representing the result of the query
Perform an xpath query on the document expecting a Number result
public queryString(query: String, ):String
-
Parameters
- query
- the xpath query
-
Returns
- String
- a string value representing the result of the query
Perform an xpath query on the document expecting a String result
public serialize(writer: Writer, ):Void
-
Parameters
- writer
- the java.io.Writer that will receive the formated xml.
Convert the document to an XML format based on the attributes indent, doIndent, omitXMLDeclaration, encoding and standalone. Output is written to the Writer.
public toString():String
-
Returns
- String
- an XML formatted string
Convert the document to an XML formatted string based on the attributes indent, doIndent, omitXMLDeclaration, encoding and standalone.