gnu.xml.dom

Class DomDocument

Implemented Interfaces:
Cloneable, Comparable<T>, Document, DocumentEvent, DocumentTraversal, EventTarget, Node, NodeList, XPathEvaluator
Known Direct Subclasses:
DomHTMLDocument

public class DomDocument
extends DomNode
implements Document, DocumentTraversal, XPathEvaluator

"Document" and "DocumentTraversal" implementation.

Note that when this checks names for legality, it uses an approximation of the XML rules, not the real ones. Specifically, it uses Unicode rules, with sufficient tweaks to pass a majority of basic XML conformance tests. (The huge XML character tables are hairy to implement.)

Fields inherited from interface org.w3c.dom.Node

ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE

Constructor Summary

DomDocument()
Constructs a Document node, associating it with an instance of the DomImpl class.
DomDocument(DOMImplementation impl)
Constructs a Document node, associating it with the specified implementation.

Method Summary

Node
adoptNode(Node source)
Attempts to adopt a node from another document to this document.
Node
appendChild(Node newChild)
DOM L1 Appends the specified node to this node's list of children, enforcing the constraints that there be only one root element and one document type child.
Attr
createAttribute(String name)
DOM L1 Returns a newly created attribute with the specified name.
Attr
createAttributeNS(String namespaceURI, String name)
DOM L2 Returns a newly created attribute with the specified name and namespace information.
CDATASection
createCDATASection(char[] buf, int off, int len)
Returns a newly created CDATA section node with the specified value.
CDATASection
createCDATASection(String value)
DOM L1 Returns a newly created CDATA section node with the specified value.
Comment
createComment(String value)
DOM L1 Returns a newly created comment node with the specified value.
DocumentFragment
createDocumentFragment()
DOM L1 Returns a newly created document fragment.
Element
createElement(String name)
DOM L1 Returns a newly created element with the specified name.
Element
createElementNS(String namespaceURI, String name)
DOM L2 Returns a newly created element with the specified name and namespace information.
EntityReference
createEntityReference(String name)
DOM L1 Returns a newly created reference to the specified entity.
XPathExpression
createExpression(String expression, XPathNSResolver resolver)
Creates a parsed XPath expression with resolved namespaces.
XPathNSResolver
createNSResolver(Node nodeResolver)
Adapts any DOM node to resolve namespaces so that an XPath expression can be easily evaluated relative to the context of the node where it appeared within the document.
NodeIterator
createNodeIterator(Node root, int whatToShow, NodeFilter filter, boolean expandEntities)
DOM L2 (Traversal) Returns a newly created node iterator.
ProcessingInstruction
createProcessingInstruction(String target, String data)
DOM L1 Returns a newly created processing instruction.
Text
createTextNode(char[] buf, int off, int len)
Returns a newly created text node with the specified value.
Text
createTextNode(String value)
DOM L1 Returns a newly created text node with the specified value.
TreeWalker
createTreeWalker(Node root, int whatToShow, NodeFilter filter, boolean expandEntities)
Create a new TreeWalker over the subtree rooted at the specified node.
Object
evaluate(String expression, Node contextNode, XPathNSResolver resolver, short type, Object result)
Evaluates an XPath expression string and returns a result of the specified type if possible.
String
getBaseURI()
The absolute base URI of this node or null if the implementation wasn't able to obtain an absolute URI.
DocumentType
getDoctype()
DOM L1 Returns the document's DocumentType, or null.
Element
getDocumentElement()
DOM L1 Returns the document's root element, or null.
String
getDocumentURI()
The location of the document or null if undefined or if the Document was created using DOMImplementation.createDocument.
DOMConfiguration
getDomConfig()
The configuration used when Document.normalizeDocument() is invoked.
Element
getElementById(String id)
DOM L1 (relocated in DOM L2) Returns the element with the specified "ID" attribute, or null.
DOMImplementation
getImplementation()
DOM L1 Returns the document's DOMImplementation.
String
getInputEncoding()
DOM L3
String
getNodeName()
DOM L1 Returns the constant "#document".
boolean
getStrictErrorChecking()
An attribute specifying whether error checking is enforced or not.
String
getXmlEncoding()
DOM L3
boolean
getXmlStandalone()
An attribute specifying, as part of the XML declaration, whether this document is standalone.
String
getXmlVersion()
An attribute specifying, as part of the XML declaration, the version number of this document.
Node
importNode(Node src, boolean deep)
DOM L2 Makes a copy of the specified node, with all nodes "owned" by this document and with children optionally copied.
Node
insertBefore(Node newChild, Node refChild)
DOM L1 Inserts the specified node in this node's list of children, enforcing the constraints that there be only one root element and one document type child.
boolean
isDefaultNamespace(String namespaceURI)
This method checks if the specified namespaceURI is the default namespace or not.
boolean
isEqualNode(Node arg)
Tests whether two nodes are equal.
String
lookupNamespaceURI(String prefix)
Look up the namespace URI associated to the given prefix, starting from this node.
String
lookupPrefix(String namespaceURI)
Look up the prefix associated to the given namespace URI, starting from this node.
void
normalizeDocument()
This method acts as if the document was going through a save and load cycle, putting the document in a "normal" form.
Node
renameNode(Node n, String namespaceURI, String qualifiedName)
Rename an existing node of type ELEMENT_NODE or ATTRIBUTE_NODE.
Node
replaceChild(Node newChild, Node refChild)
DOM L1 Replaces the specified node in this node's list of children, enforcing the constraints that there be only one root element and one document type child.
void
setBuilding(boolean flag)
Sets the building flag.
void
setCheckWellformedness(boolean flag)
Sets whether to check for document well-formedness.
void
setCheckingCharacters(boolean flag)
Sets whether to check for document characters.
void
setDefaultAttributes(boolean flag)
Sets whether to default attributes for new elements.
void
setDocumentURI(String documentURI)
The location of the document or null if undefined or if the Document was created using DOMImplementation.createDocument.
void
setInputEncoding(String inputEncoding)
void
setStrictErrorChecking(boolean strictErrorChecking)
An attribute specifying whether error checking is enforced or not.
void
setXmlEncoding(String encoding)
void
setXmlStandalone(boolean xmlStandalone)
An attribute specifying, as part of the XML declaration, whether this document is standalone.
void
setXmlVersion(String xmlVersion)
An attribute specifying, as part of the XML declaration, the version number of this document.
static void
verifyXmlName(String name)
Deprecated. This method is deprecated and may be removed in future versions of GNU JAXP

Methods inherited from class gnu.xml.dom.DomNode

addEventListener, appendChild, clone, cloneNode, compact, compareDocumentPosition, compareTo, createEvent, dispatchEvent, getAttributes, getBaseURI, getChildNodes, getElementsByTagName, getElementsByTagNameNS, getFeature, getFirstChild, getLastChild, getLength, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isReadonly, isSameNode, isSupported, item, list, lookupNamespaceURI, lookupPrefix, makeReadonly, nameAndTypeEquals, normalize, removeChild, removeEventListener, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData, toString, trimToSize

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

DomDocument

public DomDocument()
Constructs a Document node, associating it with an instance of the DomImpl class.

Note that this constructor disables character checking. It is normally used when connecting a DOM to an XML parser, and duplicating such checks is undesirable. When used for purposes other than connecting to a parser, you should re-enable that checking.


DomDocument

protected DomDocument(DOMImplementation impl)
Constructs a Document node, associating it with the specified implementation. This should only be used in conjunction with a specialized implementation; it will normally be called by that implementation.

Method Details

adoptNode

public Node adoptNode(Node source)
Attempts to adopt a node from another document to this document. If supported, it changes the ownerDocument of the source node, its children, as well as the attached attribute nodes if there are any. If the source node has a parent it is first removed from the child list of its parent. This effectively allows moving a subtree from one document to another (unlike importNode() which create a copy of the source node instead of moving it). When it fails, applications should use Document.importNode() instead. Note that if the adopted node is already part of this document (i.e. the source and target document are the same), this method still has the effect of removing the source node from the child list of its parent, if any. The following list describes the specifics for each type of node.
ownerElementnullspecifiedtrueAttrAttr
Document
DocumentType
Specified
Entity
EntityReference
Notation

Note: Since it does not create new nodes unlike the Document.importNode() method, this method does not raise an INVALID_CHARACTER_ERR exception, and applications should use the Document.normalizeDocument() method to check if an imported name is not an XML name according to the XML version in use.

Specified by:
adoptNode in interface Document
Parameters:
source - The node to move into this document.
Returns:
The adopted node, or null if this operation fails, such as when the source node comes from a different implementation.
Throws:
DOMException - NOT_SUPPORTED_ERR: Raised if the source node is of type DOCUMENT, DOCUMENT_TYPE.
NO_MODIFICATION_ALLOWED_ERR: Raised when the source node is readonly.
Since:
DOM Level 3

appendChild

public Node appendChild(Node newChild)
DOM L1 Appends the specified node to this node's list of children, enforcing the constraints that there be only one root element and one document type child.
Specified by:
appendChild in interface Node
Overrides:
appendChild in interface DomNode

createAttribute

public Attr createAttribute(String name)
DOM L1 Returns a newly created attribute with the specified name.
Specified by:
createAttribute in interface Document

createAttributeNS

public Attr createAttributeNS(String namespaceURI,
                              String name)
DOM L2 Returns a newly created attribute with the specified name and namespace information.
Specified by:
createAttributeNS in interface Document

createCDATASection

public CDATASection createCDATASection(char[] buf,
                                       int off,
                                       int len)
Returns a newly created CDATA section node with the specified value.

createCDATASection

public CDATASection createCDATASection(String value)
DOM L1 Returns a newly created CDATA section node with the specified value.
Specified by:
createCDATASection in interface Document

createComment

public Comment createComment(String value)
DOM L1 Returns a newly created comment node with the specified value.
Specified by:
createComment in interface Document

createDocumentFragment

public DocumentFragment createDocumentFragment()
DOM L1 Returns a newly created document fragment.
Specified by:
createDocumentFragment in interface Document

createElement

public Element createElement(String name)
DOM L1 Returns a newly created element with the specified name. The node name of the created element will be equal to name. The namespace, prefix and local name will all be null.
Specified by:
createElement in interface Document

createElementNS

public Element createElementNS(String namespaceURI,
                               String name)
DOM L2 Returns a newly created element with the specified name and namespace information.
Specified by:
createElementNS in interface Document

createEntityReference

public EntityReference createEntityReference(String name)
DOM L1 Returns a newly created reference to the specified entity. The caller should populate this with the appropriate children and then mark it as readonly.
Specified by:
createEntityReference in interface Document

createExpression

public XPathExpression createExpression(String expression,
                                        XPathNSResolver resolver)
            throws XPathException,
                   DOMException
Creates a parsed XPath expression with resolved namespaces. This is useful when an expression will be reused in an application since it makes it possible to compile the expression string into a more efficient internal form and preresolve all namespace prefixes which occur within the expression.
Specified by:
createExpression in interface XPathEvaluator
Parameters:
expression - The XPath expression string to be parsed.
resolver - The resolver permits translation of all prefixes, including the xml namespace prefix, within the XPath expression into appropriate namespace URIs. If this is specified as null, any namespace prefix within the expression will result in DOMException being thrown with the code NAMESPACE_ERR.
Returns:
The compiled form of the XPath expression.
Throws:
XPathException - INVALID_EXPRESSION_ERR: Raised if the expression is not legal according to the rules of the XPathEvaluator.
DOMException - NAMESPACE_ERR: Raised if the expression contains namespace prefixes which cannot be resolved by the specified XPathNSResolver.

createNSResolver

public XPathNSResolver createNSResolver(Node nodeResolver)
Adapts any DOM node to resolve namespaces so that an XPath expression can be easily evaluated relative to the context of the node where it appeared within the document. This adapter works like the DOM Level 3 method lookupNamespaceURI on nodes in resolving the namespaceURI from a given prefix using the current information available in the node's hierarchy at the time lookupNamespaceURI is called. also correctly resolving the implicit xml prefix.
Specified by:
createNSResolver in interface XPathEvaluator
Parameters:
nodeResolver - The node to be used as a context for namespace resolution.
Returns:
XPathNSResolver which resolves namespaces with respect to the definitions in scope for a specified node.

createNodeIterator

public NodeIterator createNodeIterator(Node root,
                                       int whatToShow,
                                       NodeFilter filter,
                                       boolean expandEntities)
DOM L2 (Traversal) Returns a newly created node iterator. Don't forget to detach this iterator when you're done using it!
Specified by:
createNodeIterator in interface DocumentTraversal
See Also:
DomIterator

createProcessingInstruction

public ProcessingInstruction createProcessingInstruction(String target,
                                                         String data)
DOM L1 Returns a newly created processing instruction.
Specified by:
createProcessingInstruction in interface Document

createTextNode

public Text createTextNode(char[] buf,
                           int off,
                           int len)
Returns a newly created text node with the specified value.

createTextNode

public Text createTextNode(String value)
DOM L1 Returns a newly created text node with the specified value.
Specified by:
createTextNode in interface Document

createTreeWalker

public TreeWalker createTreeWalker(Node root,
                                   int whatToShow,
                                   NodeFilter filter,
                                   boolean expandEntities)
Create a new TreeWalker over the subtree rooted at the specified node.
Specified by:
createTreeWalker in interface DocumentTraversal
Parameters:
root - The node which will serve as the root for the TreeWalker. The whatToShow flags and the NodeFilter are not considered when setting this value; any node type will be accepted as the root. The currentNode of the TreeWalker is initialized to this node, whether or not it is visible. The root functions as a stopping point for traversal methods that look upward in the document structure, such as parentNode and nextNode. The root must not be null.
whatToShow - This flag specifies which node types may appear in the logical view of the tree presented by the TreeWalker. See the description of NodeFilter for the set of possible SHOW_ values.These flags can be combined using OR.
filter - The NodeFilter to be used with this TreeWalker, or null to indicate no filter.
Returns:
The newly created TreeWalker.
Throws:
DOMException - NOT_SUPPORTED_ERR: Raised if the specified root is null.

evaluate

public Object evaluate(String expression,
                       Node contextNode,
                       XPathNSResolver resolver,
                       short type,
                       Object result)
            throws XPathException,
                   DOMException
Evaluates an XPath expression string and returns a result of the specified type if possible.
Specified by:
evaluate in interface XPathEvaluator
Parameters:
expression - The XPath expression string to be parsed and evaluated.
contextNode - The context is context node for the evaluation of this XPath expression. If the XPathEvaluator was obtained by casting the Document then this must be owned by the same document and must be a Document, Element, Attribute, Text, CDATASection, Comment, ProcessingInstruction, or XPathNamespace node. If the context node is a Text or a CDATASection, then the context is interpreted as the whole logical text node as seen by XPath, unless the node is empty in which case it may not serve as the XPath context.
resolver - The resolver permits translation of all prefixes, including the xml namespace prefix, within the XPath expression into appropriate namespace URIs. If this is specified as null, any namespace prefix within the expression will result in DOMException being thrown with the code NAMESPACE_ERR.
type - If a specific type is specified, then the result will be returned as the corresponding type.For XPath 1.0 results, this must be one of the codes of the XPathResult interface.
result - The result specifies a specific result object which may be reused and returned by this method. If this is specified as nullor the implementation does not reuse the specified result, a new result object will be constructed and returned.For XPath 1.0 results, this object will be of type XPathResult.
Returns:
The result of the evaluation of the XPath expression.For XPath 1.0 results, this object will be of type XPathResult.
Throws:
XPathException - INVALID_EXPRESSION_ERR: Raised if the expression is not legal according to the rules of the XPathEvaluatori
TYPE_ERR: Raised if the result cannot be converted to return the specified type.
DOMException - NAMESPACE_ERR: Raised if the expression contains namespace prefixes which cannot be resolved by the specified XPathNSResolver.
WRONG_DOCUMENT_ERR: The Node is from a document that is not supported by this XPathEvaluator.
NOT_SUPPORTED_ERR: The Node is not a type permitted as an XPath context node or the request type is not permitted by this XPathEvaluator.

getBaseURI

public String getBaseURI()
The absolute base URI of this node or null if the implementation wasn't able to obtain an absolute URI. This value is computed as described in . However, when the Document supports the feature "HTML" [DOM Level 2 HTML] , the base URI is computed using first the value of the href attribute of the HTML BASE element if any, and the value of the documentURI attribute from the Document interface otherwise.
Specified by:
getBaseURI in interface Node
Overrides:
getBaseURI in interface DomNode
Since:
DOM Level 3

getDoctype

public final DocumentType getDoctype()
DOM L1 Returns the document's DocumentType, or null.
Specified by:
getDoctype in interface Document

getDocumentElement

public final Element getDocumentElement()
DOM L1 Returns the document's root element, or null.
Specified by:
getDocumentElement in interface Document

getDocumentURI

public String getDocumentURI()
The location of the document or null if undefined or if the Document was created using DOMImplementation.createDocument. No lexical checking is performed when setting this attribute; this could result in a null value returned when using Node.baseURI .
Beware that when the Document supports the feature "HTML" [DOM Level 2 HTML] , the href attribute of the HTML BASE element takes precedence over this attribute when computing Node.baseURI.
Specified by:
getDocumentURI in interface Document
Since:
DOM Level 3

getDomConfig

public DOMConfiguration getDomConfig()
The configuration used when Document.normalizeDocument() is invoked.
Specified by:
getDomConfig in interface Document
Since:
DOM Level 3

getElementById

public Element getElementById(String id)
DOM L1 (relocated in DOM L2) Returns the element with the specified "ID" attribute, or null.

Returns null unless Consumer was used to populate internal DTD declaration information, using package-private APIs. If that internal DTD information is available, the document may be searched for the element with that ID.

Specified by:
getElementById in interface Document

getImplementation

public final DOMImplementation getImplementation()
DOM L1 Returns the document's DOMImplementation.
Specified by:
getImplementation in interface Document

getInputEncoding

public String getInputEncoding()
DOM L3
Specified by:
getInputEncoding in interface Document

getNodeName

public final String getNodeName()
DOM L1 Returns the constant "#document".
Specified by:
getNodeName in interface Node
Overrides:
getNodeName in interface DomNode

getStrictErrorChecking

public boolean getStrictErrorChecking()
An attribute specifying whether error checking is enforced or not. When set to false, the implementation is free to not test every possible error case normally defined on DOM operations, and not raise any DOMException on DOM operations or report errors while using Document.normalizeDocument(). In case of error, the behavior is undefined. This attribute is true by default.
Specified by:
getStrictErrorChecking in interface Document
Since:
DOM Level 3

getXmlEncoding

public String getXmlEncoding()
DOM L3
Specified by:
getXmlEncoding in interface Document

getXmlStandalone

public boolean getXmlStandalone()
An attribute specifying, as part of the XML declaration, whether this document is standalone. This is false when unspecified.

Note: No verification is done on the value when setting this attribute. Applications should use Document.normalizeDocument() with the "validate" parameter to verify if the value matches the validity constraint for standalone document declaration as defined in [XML 1.0].

Specified by:
getXmlStandalone in interface Document
Since:
DOM Level 3

getXmlVersion

public String getXmlVersion()
An attribute specifying, as part of the XML declaration, the version number of this document. If there is no declaration and if this document supports the "XML" feature, the value is "1.0". If this document does not support the "XML" feature, the value is always null. Changing this attribute will affect methods that check for invalid characters in XML names. Application should invoke Document.normalizeDocument() in order to check for invalid characters in the Nodes that are already part of this Document.
DOM applications may use the DOMImplementation.hasFeature(feature, version) method with parameter values "XMLVersion" and "1.0" (respectively) to determine if an implementation supports [XML 1.0]. DOM applications may use the same method with parameter values "XMLVersion" and "1.1" (respectively) to determine if an implementation supports [XML 1.1]. In both cases, in order to support XML, an implementation must also support the "XML" feature defined in this specification. Document objects supporting a version of the "XMLVersion" feature must not raise a NOT_SUPPORTED_ERR exception for the same version number when using Document.xmlVersion.
Specified by:
getXmlVersion in interface Document
Since:
DOM Level 3

importNode

public Node importNode(Node src,
                       boolean deep)
DOM L2 Makes a copy of the specified node, with all nodes "owned" by this document and with children optionally copied. This type of standard utility has become, well, a standard utility.

Note that EntityReference nodes created through this method (either directly, or recursively) never have children, and that there is no portable way to associate them with such children.

Note also that there is no requirement that the specified node be associated with a different document. This differs from the cloneNode operation in that the node itself is not given an opportunity to participate, so that any information managed by node subclasses will be lost.

Specified by:
importNode in interface Document

insertBefore

public Node insertBefore(Node newChild,
                         Node refChild)
DOM L1 Inserts the specified node in this node's list of children, enforcing the constraints that there be only one root element and one document type child.
Specified by:
insertBefore in interface Node
Overrides:
insertBefore in interface DomNode

isDefaultNamespace

public boolean isDefaultNamespace(String namespaceURI)
This method checks if the specified namespaceURI is the default namespace or not.
Specified by:
isDefaultNamespace in interface Node
Overrides:
isDefaultNamespace in interface DomNode
Parameters:
namespaceURI - The namespace URI to look for.
Returns:
Returns true if the specified namespaceURI is the default namespace, false otherwise.
Since:
DOM Level 3

isEqualNode

public boolean isEqualNode(Node arg)
Tests whether two nodes are equal.
This method tests for equality of nodes, not sameness (i.e., whether the two nodes are references to the same object) which can be tested with Node.isSameNode(). All nodes that are the same will also be equal, though the reverse may not be true.
Two nodes are equal if and only if the following conditions are satisfied:
  • The two nodes are of the same type.
  • The following string attributes are equal: nodeName, localName, namespaceURI, prefix, nodeValue . This is: they are both null, or they have the same length and are character for character identical.
  • The attributes NamedNodeMaps are equal. This is: they are both null, or they have the same length and for each node that exists in one map there is a node that exists in the other map and is equal, although not necessarily at the same index.
  • The childNodes NodeLists are equal. This is: they are both null, or they have the same length and contain equal nodes at the same index. Note that normalization can affect equality; to avoid this, nodes should be normalized before being compared.

For two DocumentType nodes to be equal, the following conditions must also be satisfied:
  • The following string attributes are equal: publicId, systemId, internalSubset.
  • The entities NamedNodeMaps are equal.
  • The notations NamedNodeMaps are equal.

On the other hand, the following do not affect equality: the ownerDocument, baseURI, and parentNode attributes, the specified attribute for Attr nodes, the schemaTypeInfo attribute for Attr and Element nodes, the Text.isElementContentWhitespace attribute for Text nodes, as well as any user data or event listeners registered on the nodes.

Note: As a general rule, anything not mentioned in the description above is not significant in consideration of equality checking. Note that future versions of this specification may take into account more attributes and implementations conform to this specification are expected to be updated accordingly.

Specified by:
isEqualNode in interface Node
Overrides:
isEqualNode in interface DomNode
Parameters:
arg - The node to compare equality with.
Returns:
Returns true if the nodes are equal, false otherwise.
Since:
DOM Level 3

lookupNamespaceURI

public String lookupNamespaceURI(String prefix)
Look up the namespace URI associated to the given prefix, starting from this node.
See for details on the algorithm used by this method.
Specified by:
lookupNamespaceURI in interface Node
Overrides:
lookupNamespaceURI in interface DomNode
Parameters:
prefix - The prefix to look for. If this parameter is null, the method will return the default namespace URI if any.
Returns:
Returns the associated namespace URI or null if none is found.
Since:
DOM Level 3

lookupPrefix

public String lookupPrefix(String namespaceURI)
Look up the prefix associated to the given namespace URI, starting from this node. The default namespace declarations are ignored by this method.
See for details on the algorithm used by this method.
Specified by:
lookupPrefix in interface Node
Overrides:
lookupPrefix in interface DomNode
Parameters:
namespaceURI - The namespace URI to look for.
Returns:
Returns an associated namespace prefix if found or null if none is found. If more than one prefix are associated to the namespace prefix, the returned namespace prefix is implementation dependent.
Since:
DOM Level 3

normalizeDocument

public void normalizeDocument()
This method acts as if the document was going through a save and load cycle, putting the document in a "normal" form. As a consequence, this method updates the replacement tree of EntityReference nodes and normalizes Text nodes, as defined in the method Node.normalize().
Otherwise, the actual result depends on the features being set on the Document.domConfig object and governing what operations actually take place. Noticeably this method could also make the document namespace well-formed according to the algorithm described in , check the character normalization, remove the CDATASection nodes, etc. See DOMConfiguration for details.
// Keep in the document 
 the information defined // in the XML Information Set (Java example) 
 DOMConfiguration docConfig = myDocument.getDomConfig(); 
 docConfig.setParameter("infoset", Boolean.TRUE); 
 myDocument.normalizeDocument();

Mutation events, when supported, are generated to reflect the changes occurring on the document.
If errors occur during the invocation of this method, such as an attempt to update a read-only node or a Node.nodeName contains an invalid character according to the XML version in use, errors or warnings (DOMError.SEVERITY_ERROR or DOMError.SEVERITY_WARNING) will be reported using the DOMErrorHandler object associated with the "error-handler " parameter. Note this method might also report fatal errors ( DOMError.SEVERITY_FATAL_ERROR) if an implementation cannot recover from an error.
Specified by:
normalizeDocument in interface Document
Since:
DOM Level 3

renameNode

public Node renameNode(Node n,
                       String namespaceURI,
                       String qualifiedName)
            throws DOMException
Rename an existing node of type ELEMENT_NODE or ATTRIBUTE_NODE.
When possible this simply changes the name of the given node, otherwise this creates a new node with the specified name and replaces the existing node with the new node as described below.
If simply changing the name of the given node is not possible, the following operations are performed: a new node is created, any registered event listener is registered on the new node, any user data attached to the old node is removed from that node, the old node is removed from its parent if it has one, the children are moved to the new node, if the renamed node is an Element its attributes are moved to the new node, the new node is inserted at the position the old node used to have in its parent's child nodes list if it has one, the user data that was attached to the old node is attached to the new node.
When the node being renamed is an Element only the specified attributes are moved, default attributes originated from the DTD are updated according to the new element name. In addition, the implementation may update default attributes from other schemas. Applications should use Document.normalizeDocument() to guarantee these attributes are up-to-date.
When the node being renamed is an Attr that is attached to an Element, the node is first removed from the Element attributes map. Then, once renamed, either by modifying the existing node or creating a new one as described above, it is put back.
In addition,
  • a user data event NODE_RENAMED is fired,
  • when the implementation supports the feature "MutationNameEvents", each mutation operation involved in this method fires the appropriate event, and in the end the event { http://www.w3.org/2001/xml-events, DOMElementNameChanged} or { http://www.w3.org/2001/xml-events, DOMAttributeNameChanged} is fired.
Specified by:
renameNode in interface Document
Parameters:
n - The node to rename.
namespaceURI - The new namespace URI.
qualifiedName - The new qualified name.
Returns:
The renamed node. This is either the specified node or the new node that was created to replace the specified node.
Throws:
DOMException - NOT_SUPPORTED_ERR: Raised when the type of the specified node is neither ELEMENT_NODE nor ATTRIBUTE_NODE, or if the implementation does not support the renaming of the document element.
INVALID_CHARACTER_ERR: Raised if the new qualified name is not an XML name according to the XML version in use specified in the Document.xmlVersion attribute.
WRONG_DOCUMENT_ERR: Raised when the specified node was created from a different document than this document.
NAMESPACE_ERR: Raised if the qualifiedName is a malformed qualified name, if the qualifiedName has a prefix and the namespaceURI is null, or if the qualifiedName has a prefix that is "xml" and the namespaceURI is different from " http://www.w3.org/XML/1998/namespace" [XML Namespaces] . Also raised, when the node being renamed is an attribute, if the qualifiedName, or its prefix, is "xmlns" and the namespaceURI is different from "http://www.w3.org/2000/xmlns/".
Since:
DOM Level 3

replaceChild

public Node replaceChild(Node newChild,
                         Node refChild)
DOM L1 Replaces the specified node in this node's list of children, enforcing the constraints that there be only one root element and one document type child.
Specified by:
replaceChild in interface Node
Overrides:
replaceChild in interface DomNode

setBuilding

public void setBuilding(boolean flag)
Sets the building flag. Mutation events in the document are not reported.

setCheckWellformedness

public void setCheckWellformedness(boolean flag)
Sets whether to check for document well-formedness. If true, an exception will be raised if a second doctype or root element node is added to the document.

setCheckingCharacters

public void setCheckingCharacters(boolean flag)
Sets whether to check for document characters.

setDefaultAttributes

public void setDefaultAttributes(boolean flag)
Sets whether to default attributes for new elements.

setDocumentURI

public void setDocumentURI(String documentURI)
The location of the document or null if undefined or if the Document was created using DOMImplementation.createDocument. No lexical checking is performed when setting this attribute; this could result in a null value returned when using Node.baseURI .
Beware that when the Document supports the feature "HTML" [DOM Level 2 HTML] , the href attribute of the HTML BASE element takes precedence over this attribute when computing Node.baseURI.
Specified by:
setDocumentURI in interface Document
Since:
DOM Level 3

setInputEncoding

public void setInputEncoding(String inputEncoding)

setStrictErrorChecking

public void setStrictErrorChecking(boolean strictErrorChecking)
An attribute specifying whether error checking is enforced or not. When set to false, the implementation is free to not test every possible error case normally defined on DOM operations, and not raise any DOMException on DOM operations or report errors while using Document.normalizeDocument(). In case of error, the behavior is undefined. This attribute is true by default.
Specified by:
setStrictErrorChecking in interface Document
Since:
DOM Level 3

setXmlEncoding

public void setXmlEncoding(String encoding)

setXmlStandalone

public void setXmlStandalone(boolean xmlStandalone)
An attribute specifying, as part of the XML declaration, whether this document is standalone. This is false when unspecified.

Note: No verification is done on the value when setting this attribute. Applications should use Document.normalizeDocument() with the "validate" parameter to verify if the value matches the validity constraint for standalone document declaration as defined in [XML 1.0].

Specified by:
setXmlStandalone in interface Document
Throws:
DOMException - NOT_SUPPORTED_ERR: Raised if this document does not support the "XML" feature.
Since:
DOM Level 3

setXmlVersion

public void setXmlVersion(String xmlVersion)
An attribute specifying, as part of the XML declaration, the version number of this document. If there is no declaration and if this document supports the "XML" feature, the value is "1.0". If this document does not support the "XML" feature, the value is always null. Changing this attribute will affect methods that check for invalid characters in XML names. Application should invoke Document.normalizeDocument() in order to check for invalid characters in the Nodes that are already part of this Document.
DOM applications may use the DOMImplementation.hasFeature(feature, version) method with parameter values "XMLVersion" and "1.0" (respectively) to determine if an implementation supports [XML 1.0]. DOM applications may use the same method with parameter values "XMLVersion" and "1.1" (respectively) to determine if an implementation supports [XML 1.1]. In both cases, in order to support XML, an implementation must also support the "XML" feature defined in this specification. Document objects supporting a version of the "XMLVersion" feature must not raise a NOT_SUPPORTED_ERR exception for the same version number when using Document.xmlVersion.
Specified by:
setXmlVersion in interface Document
Throws:
DOMException - NOT_SUPPORTED_ERR: Raised if the version is set to a value that is not supported by this Document or if this document does not support the "XML" feature.
Since:
DOM Level 3

verifyXmlName

public static void verifyXmlName(String name)

Deprecated. This method is deprecated and may be removed in future versions of GNU JAXP

Throws a DOM exception if the specified name is not a legal XML 1.0 Name.

DomDocument.java -- Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.