Java Reference
In-Depth Information
createCDATASection(String data)
Returns a reference to a
CDATASection
node with
the value
data
. Throws a
DOMException
if you
try to create this node if the
Document
object
encapsulates an HTML document.
createEntityReference(
String name)
Returns a reference to an
EntityReference
node with the name specified. Throws a
DOMException
with the code
INVALID
_
CHARACTER
_
ERR
if
name
contains
invalid characters and
NOT
_
SUPPORTED
_
ERR
if the
Document
object is an HTML document.
createProcessingInstruction(
Returns a reference to a
ProcessingInstruction
node with the
specified name and target. Throws a
DOMException
with the code
INVALID
_
CHARACTER
_
ERR
if
target
contains
illegal characters and
NOT
_
SUPPORTED
_
ERR
if the
Document
object is an HTML document.
String target,
String name)
createDocumentFragment()
Creates an empty
DocumentFragment
object.
You can insert a
DocumentFragment
object into
a
Document
object using methods that the
Document
interface (and the
DocumentFragment
interface) inherits from the
Node
interface. You can
use the same methods to insert nodes into a
DocumentFragment
object.
The references to HTML in the table above arise because a
Document
object can be used to encapsulate an
HTML document. Our interest is purely XML so we won't be discussing this aspect further.
Of course, having a collection of nodes within a document does not define any structure. In order to
establish the structure of a document you have to associate each attribute node that you have created
with the appropriate element, and you must also make sure that each element other than the root is a
child of some element. Along with all the other types of node, the
Element
interface inherits two
methods from the
Node
interface that enable you to make one node a child of another:
appendChild(
Node child)
Appends the node
child
to the end of the list of existing child
nodes. This method throws a
DOMException
with the code
HIERARCHY
_
REQUEST
_
ERR
if the current node does not allow
children, the code
WRONG
_
DOCUMENT
_
ERR
if child belongs to
another document, or the code
NO
_
MODIFICATION
_
ALLOWED
_
ERR
if the current node is read-
only.
insertBefore(
Node child,
Insert
child
as a child node immediately before
existing
in
the current list of child nodes. This method can throw
DOMException
with the same error codes as above, plus
NOT
_
FOUND
_
ERR
if
existing
is not a child of the current
node.
Node existing)