Java Reference
In-Depth Information
Of course, you can also output the stack trace, return from the method, or even end the program here if
you want.
Adding to a Document
The
Document
interface declares methods for adding nodes to a
Document
object. You can create
nodes encapsulating elements, attributes, text, entity references, comments,
CDATA
sections, and
processing instructions so you can assemble a
Document
object representing a complete XML
document. The methods declared by the
Document
interface are:
createElement(String name)
Returns a reference to an
Element
object
encapsulating an element with
name
as the tag
name. The method will throw an exception of type
DOMException
with
INVALID
_
CHARACTER
_
ERR
set if
name
contains an invalid character.
createElementNS(
String nsURI,
Returns a reference to an
Element
object
encapsulating an element with
qualifiedName
as
the tag name in the namespace
nsURI
. The method
will throw an exception of type
DOMException
with
INVALID
_
CHARACTER
_
ERR
set if
qualifiedName
contains an invalid character or
NAMESPACE
_
ERR
if it has a prefix
"xml"
and
nsURI
is not
http://www.w3.org/XML/1998/namespace
.
String qualifiedName)
createAttribute(String name)
Returns a reference to an
Attr
object
encapsulating an attribute with
name
as the
attribute name and its value as
""
. The method will
throw an exception of type
DOMException
with
INVALID
_
CHARACTER
_
ERR
set if
name
contains
an invalid character.
createAttribute(
Returns a reference to an
Attr
object
encapsulating an attribute with
qualifiedName
as
the attribute name in the namespace
nsURI
and its
value as
""
. The method will throw an exception of
type
DOMException
with
INVALID
_
CHARACTER
_
ERR
set if the name
contains an invalid character or
NAMESPACE
_
ERR
if
the name conflicts with the namespace.
String nsURI,
String qualifiedName)
createTextNode(String text)
Returns a reference to a
Text
node containing the
string
text
.
createComment(String comment)
Returns a reference to a
Comment
node containing
the string
comment
.