Java Reference
In-Depth Information
break;
}
System.err.println(e.getMessage());
}
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 org.w3c.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 the following:
Element createElement(String name) : Returns a reference to an object encapsulating an
element with name as the tag name. The method throws a DOMException with
INVALID_CHARACTER_ERR set if name contains an invalid character.
Element createElementNS(String nsURI, String qualifiedName) : Returns a reference
to an object encapsulating an element with qualifiedName as the tag name in the namespace
nsURI . The method throws a 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 ht-
tp://www.w3.org/XML/1998/namespace .
Attr createAttribute(String name) : Returns a reference to an Attr object with name
as the attribute name and its value as "" . The method throws a DOMException with
INVALID_CHARACTER_ERR set if name contains an invalid character.
Attr createAttribute(String nsURI, String qualifiedName) : Returns a reference to an
Attr object with qualifiedName as the attribute name in the namespace nsURI and its value as
"" . The method throws a DOMException with INVALID_CHARACTER_ERR set if the name contains
an invalid character or NAMESPACE_ERR if the name conflicts with the namespace.
Text createTextNode(String text) : Returns a reference to a node containing the string text .
Comment createComment(String comment) : Returns a reference to a node containing the string
comment .
CDATASection createCDATASection(String data) : Returns a reference to a node with the
value data . Throws a DOMException if you try to create this node when the Document object en-
capsulates an HTML document.
EntityReference createEntityReference(String name) :Returns a reference to an 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 docu-
ment.
ProcessingInstruction createProcessingInstruction(String target,String
name) :Returns a reference to a 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.
DocumentFragment createDocumentFragment() : Creates an empty object. You can insert a
DocumentFragment object into a Document object using methods that the Document and Docu-
Search WWH ::




Custom Search