A representation of an XML document.
Methods
Method | Return type | Brief description |
---|---|---|
Document
|
Appends the given node to the end of the document. | |
Document
|
Inserts the given node at the given index among all nodes that are immediate children of the document. | |
Content[]
|
Creates unattached copies of all nodes that are immediate children of the document. | |
Element
|
Detaches and returns the document's root Element
node. |
|
Content[]
|
Gets all nodes that are immediate children of the document. | |
Content
|
Gets the node at the given index among all nodes that are immediate children of the document. | |
Integer
|
Gets the number of nodes that are immediate children of the document. | |
Content[]
|
Gets all nodes that are direct or indirect children of the document, in the order they appear in the document. | |
Doc
|
Gets the document's Doc
declaration. |
|
Element
|
Gets the document's root Element
node. |
|
Boolean
|
Determines whether the document has a root Element
node. |
|
Content[]
|
Removes all nodes that are immediate children of the document. | |
Boolean
|
Removes the given node, if the node is an immediate child of the document. | |
Content
|
Removes the node at the given index among all nodes that are immediate children of the document. | |
Document
|
Sets the document's Doc
declaration. |
|
Document
|
Sets the document's root Element
node. |
Detailed documentation
add
Content(content)
Appends the given node to the end of the document. The content
argument can be a Content
object or any node object that corresponds to a type listed in Content
. Note, however, that a document can only have one child Element
node, which is implicitly the root Element
node.
Parameters
Name | Type | Description |
---|---|---|
content
|
Content
|
the node to append |
Return
Document
— the document, for chaining
add
Content(index, content)
Inserts the given node at the given index among all nodes that are immediate children of the
document. The content
argument can be a Content
object or any node object
that corresponds to a type listed in Content
. Note, however, that a document
can only have one child Element
node, which is implicitly the root Element
node.
Parameters
Name | Type | Description |
---|---|---|
index
|
Integer
|
the index at which to insert the node among all nodes that are immediate children of the document |
content
|
Content
|
the node to insert |
Return
Document
— the document, for chaining
clone
Content()
Creates unattached copies of all nodes that are immediate children of the document.
Return
Content[]
— an array of unattached copies of all nodes that are immediate children of the
document
detach
Root
Element()
get
All
Content()
Gets all nodes that are immediate children of the document.
Return
Content[]
— an array of all nodes that are immediate children of the document
get
Content(index)
Gets the node at the given index among all nodes that are immediate children of the
document. If there is no node at the given index, this method returns null
.
Parameters
Name | Type | Description |
---|---|---|
index
|
Integer
|
the index for the node among all nodes that are immediate children of the document |
Return
Content
— the node, or null
if there is no node at the given index
get
Content
Size()
Gets the number of nodes that are immediate children of the document.
Return
Integer
— the number of nodes that are immediate children of the document
get
Descendants()
Gets all nodes that are direct or indirect children of the document, in the order they appear in the document.
Return
Content[]
— an array of all nodes that are direct or indirect children of the document
get
Doc
Type()
get
Root
Element()
has
Root
Element()
Determines whether the document has a root Element
node.
Return
Boolean
— true
if the document has a root Element
node; false
if not
remove
Content()
Removes all nodes that are immediate children of the document.
Return
Content[]
— an array of all nodes that were immediate children of the document before they
were removed
remove
Content(content)
Removes the given node, if the node is an immediate child of the document. The content
argument can be a Content
object or any node object that corresponds to a
type listed in Content
.
Parameters
Name | Type | Description |
---|---|---|
content
|
Content
|
the node to remove |
Return
Boolean
— true
if the node was an immediate child and was removed; false
if not
remove
Content(index)
Removes the node at the given index among all nodes that are immediate children of the
document. If there is no node at the given index, this method returns null
.
Parameters
Name | Type | Description |
---|---|---|
index
|
Integer
|
the index for the node among all nodes that are immediate children of the document |
Return
Content
— the node that was removed, or null
if there is no node at the given index
set
Doc
Type(docType)
Sets the document's Doc
declaration. If the document already has a different Doc
node, this method overwrites the old node. This method throws an exception if
the document already contains the same Doc
node that is being set.
Parameters
Name | Type | Description |
---|---|---|
doc
|
Doc
|
the Document
to set |
Return
Document
— the document, for chaining