Java Reference
In-Depth Information
•
INVALID_CHARACTER_ERR
: An invalid character has been specified. In the previous code fragment
this would mean the second argument to
createDocument()
specifying the root element name
contains an invalid character.
•
DOMSTRING_SIZE_ERR
: The specified range of text does not fit into a
DOMString
value. A
DOMString
value is defined in the DOM Level 3 specification and is equivalent to a Java
String
type.
•
HIERARCHY_REQUEST_ERR
: You tried to insert a node where it doesn't belong.
•
WRONG_DOCUMENT_ERR
: You tried to use a node in a different document from the one that created
it.
•
NO_DATA_ALLOWED_ERR
: You specified data for a node that does not support data.
•
NO_MODIFICATION_ALLOWED_ERR
: You attempted to modify an object where modifications are
prohibited.
•
NOT_FOUND_ERR
: You tried to reference a node that does not exist.
•
NOT_SUPPORTED_ERR
: The object type or operation that you requested is not supported.
•
INUSE_ATTRIBUTE_ERR
: You tried to add an attribute that is in use elsewhere.
•
INVALID_STATE_ERR
: You tried to use an object that is not usable.
•
SYNTAX_ERR
: You specified an invalid or illegal string.
•
INVALID_MODIFICATION_ERR
: You tried to modify the type of the underlying object.
•
NAMESPACE_ERR
: You tried to create or modify an object such that it would be inconsistent with
namespaces in the document.
•
INVALID_ACCESS_ERR
: A parameter or operation is not supported by the underlying object.
•
VALIDATION_ERR
: An operation to remove or insert a node relative to an existing node would
make the node invalid.
•
TYPE_MISMATCH_ERR
: The type of an object is not compatible with the expected type of the para-
meter associated with the object.
•
WRONG_DOCUMENT_ERR
: The document does not support the
DocumentType
node specified.
The
createDocument()
method can throw a
DOMException
with
code
set to
INVALID_CHARACTER_ERR
,
NAMESPACE_ERR
,
NOT_SUPPORTED_ERR
, or
WRONG_DOCUMENT_ERR
. The
createDocumentType()
method can
also throw a
DOMException
with
code
set to any of the first three values for
createDocument()
.
You therefore might code the
catch
block in the previous fragment like this:
catch(DOMException e) {
switch(e.code) {
case DOMException.INVALID_CHARACTER_ERR:
System.err.println("Qualified name contains an invalid character.");
break;
case DOMException.NAMESPACE_ERR:
System.err.println("Qualified name is malformed or invalid.");
break;
case DOMException.WRONG_DOCUMENT_ERR:
System.err.println("Document does not support this doctype");
break;
case DOMException.NOT_SUPPORTED_ERR:
System.err.println("Implementation does not support XML.");
break;
default:
System.err.println("Code not recognized: " + e.code);