Top Description Fields Constructors Methods
com.sun.org.apache.xerces.internal.dom

public Class CoreDocumentImpl

extends ParentNode
implements Document
Class Inheritance
All Implemented Interfaces
org.w3c.dom.Document, org.w3c.dom.Node
Known Direct Subclasses
com.sun.org.apache.xerces.internal.dom.DocumentImpl
Imports
com.sun.org.apache.xerces.internal.impl.Constants, com.sun.org.apache.xerces.internal.util.URI, .XML11Char, .XMLChar, com.sun.org.apache.xerces.internal.utils.ObjectFactory, com.sun.org.apache.xerces.internal.xni.NamespaceContext, java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .ObjectStreamField, java.lang.reflect.Constructor, java.util.HashMap, .Hashtable, .Map, jdk.xml.internal.SecuritySupport, org.w3c.dom.Attr, .CDATASection, .Comment, .DOMConfiguration, .DOMException, .DOMImplementation, .Document, .DocumentFragment, .DocumentType, .Element, .Entity, .EntityReference, .NamedNodeMap, .Node, .NodeList, .Notation, .ProcessingInstruction, .Text, .UserDataHandler, org.w3c.dom.events.Event, .EventListener, org.w3c.dom.ls.DOMImplementationLS, .LSSerializer

The Document interface represents the entire HTML or XML document. Conceptually, it is the root of the document tree, and provides the primary access to the document's data.

Since elements, text nodes, comments, processing instructions, etc. cannot exist outside the context of a Document, the Document interface also contains the factory methods needed to create these objects. The Node objects created have a ownerDocument attribute which associates them with the Document within whose context they were created.

The CoreDocumentImpl class only implements the DOM Core. Additional modules are supported by the more complete DocumentImpl subclass.

Note

When any node in the document is serialized, the entire document is serialized along with it.

Authors
Arnaud Le Hors, IBM, Joe Kesselman, IBM, Andy Clark, IBM, Ralf Pfeiffer, IBM
Since
PR-DOM-Level-1-19980818.

Field Summary

Modifier and TypeField and Description
protected String
actualEncoding

Experimental DOM Level 3 feature: Document actualEncoding

protected boolean
allowGrammarAccess

Allow grammar access.

protected boolean
ancestorChecking

Ancestor checking

protected int
changes

Number of alterations made to this document since its creation.

protected ElementImpl
docElement

Document element.

protected DocumentTypeImpl
docType

Document type.

private int
documentNumber

The following are required for compareDocumentPosition

pack-priv transient DOMNormalizer
protected String
encoding

Experimental DOM Level 3 feature: Document encoding

protected boolean
errorChecking

Bypass error checking.

pack-priv transient DOMConfigurationImpl
protected String
fDocumentURI

Experimental DOM Level 3 feature: documentURI

pack-priv transient NodeListCache
fFreeNLCache

NodeListCache free list

pack-priv transient Object
protected Map<String, Node>
identifiers

Identifiers.

private static final int[]
kidOK

Table for quick check of child insertion.

private int
private Map<Node, Integer>
private Map<Node, Map<String, ParentNode.UserDataRecord>>
nodeUserData

Table for user data attached to this document nodes.

private static final ObjectStreamField[]
pack-priv static final long
protected boolean
standalone

Experimental DOM Level 3 feature: Document standalone

protected String
version

Experimental DOM Level 3 feature: Document version

private boolean
protected boolean
Inherited from com.sun.org.apache.xerces.internal.dom.ParentNode:
firstChildfNodeListCacheownerDocument

Constructor Summary

AccessConstructor and Description
public
CoreDocumentImpl()

NON-DOM: Actually creating a Document is outside the DOM's spec, since it has to operate in terms of a particular implementation.

public
CoreDocumentImpl(boolean grammarAccess)

Constructor.

public
CoreDocumentImpl(DocumentType doctype)

For DOM2 support.

public
CoreDocumentImpl(DocumentType doctype, boolean grammarAccess)

For DOM2 support.

Method Summary

Modifier and TypeMethod and Description
public void
abort()

DOM Level 3 WD - Experimental.

protected void
addEventListener(NodeImpl node, String type, EventListener listener, boolean useCapture)

public Node
adoptNode(Node
The node to adopt.
source
)

Implements org.w3c.dom.Document.adoptNode.

DOM Level 3 WD - Experimental Change the node's ownerDocument, and its subtree, to this Document

pack-priv void
callUserDataHandlers(Node
The node this operation applies to.
n
,
Node
The copy node or null.
c
,
short
The operation - import, clone, or delete.
operation
)

Call user data handlers when a node is deleted (finalized)

pack-priv void
callUserDataHandlers(Node
The node this operation applies to.
n
,
Node
The copy node or null.
c
,
short
The operation - import, clone, or delete.
operation
,
Map<String, ParentNode.UserDataRecord>
Data associated with n.
userData
)

Call user data handlers when a node is deleted (finalized)

protected void
changed()

Overrides com.sun.org.apache.xerces.internal.dom.NodeImpl.changed.

Denotes that this node has changed.

protected int
changes()

Overrides com.sun.org.apache.xerces.internal.dom.NodeImpl.changes.

Returns the number of changes to this node.

protected final void
checkDOMNSErr(String prefix, String namespace)

protected final void
checkNamespaceWF(String qname, int colon1, int colon2)

Call user data handlers to let them know the nodes they are related to are being deleted.

protected final void
checkQName(String
prefix of qualified name
prefix
,
String
local part of qualified name
local
)

Checks if the given qualified name is legal with respect to the version of XML to which this document must conform.

protected final void
clearIdentifiers()

Remove all identifiers from the ID table

public Object
clone()

Overrides java.lang.Object.clone.

Clone.

public Node

Returns:

org.w3c.dom.Node
cloneNode
(boolean
boolean, iff true replicate children
deep
)

Overrides com.sun.org.apache.xerces.internal.dom.ParentNode.cloneNode.

Implements org.w3c.dom.Node.cloneNode.

Deep-clone a document, including fixing ownerDoc for the cloned children.

protected void
cloneNode(CoreDocumentImpl newdoc, boolean deep)

internal method to share code with subclass

protected void
public Attr
createAttribute(String
The name of the attribute. Note that the attribute's value is _not_ established at the factory; remember to set it!
name
)

Implements org.w3c.dom.Document.createAttribute.

Factory method; creates an Attribute having this Document as its OwnerDoc.

public Attr

Returns:

Attr A new Attr object.
createAttributeNS
(String
The namespace URI of the attribute to create. When it is null or an empty string, this method behaves like createAttribute.
namespaceURI
,
String
The qualified name of the attribute to instantiate.
qualifiedName
)

Implements org.w3c.dom.Document.createAttributeNS.

Introduced in DOM Level 2.

public Attr

Returns:

Attr A new Attr object.
createAttributeNS
(String
The namespace URI of the attribute to create. When it is null or an empty string, this method behaves like createAttribute.
namespaceURI
,
String
The qualified name of the attribute to instantiate.
qualifiedName
,
String
The local name of the attribute to instantiate.
localpart
)

NON-DOM: a factory method used by the Xerces DOM parser to create an element.

public CDATASection
createCDATASection(String
The initial contents of the CDATA
data
)

Implements org.w3c.dom.Document.createCDATASection.

Factory method; creates a CDATASection having this Document as its OwnerDoc.

public Comment
createComment(String
The initial contents of the Comment.
data
)

Implements org.w3c.dom.Document.createComment.

Factory method; creates a Comment having this Document as its OwnerDoc.

public DocumentFragment
createDocumentFragment()

Implements org.w3c.dom.Document.createDocumentFragment.

Factory method; creates a DocumentFragment having this Document as its OwnerDoc.

public DocumentType
createDocumentType(String
The name of the Entity we wish to provide a value for.
qualifiedName
,
String publicID, String systemID)

NON-DOM Factory method; creates a DocumentType having this Document as its OwnerDoc.

public Element
createElement(String
The name of the element type to instantiate. For XML, this is case-sensitive. For HTML, the tagName parameter may be provided in any case, but it must be mapped to the canonical uppercase form by the DOM implementation.
tagName
)

Implements org.w3c.dom.Document.createElement.

Factory method; creates an Element having this Document as its OwnerDoc.

public ElementDefinitionImpl
createElementDefinition(String name)

NON-DOM Factory method: creates an element definition.

public Element

Returns:

Element A new Element object with the following attributes:
createElementNS
(String
The namespace URI of the element to create.
namespaceURI
,
String
The qualified name of the element type to instantiate.
qualifiedName
)

Implements org.w3c.dom.Document.createElementNS.

Introduced in DOM Level 2.

public Element

Returns:

Element A new Element object with the following attributes:
createElementNS
(String
The namespace URI of the element to create.
namespaceURI
,
String
The qualified name of the element type to instantiate.
qualifiedName
,
String
The local name of the attribute to instantiate.
localpart
)

NON-DOM: a factory method used by the Xerces DOM parser to create an element.

public Entity
createEntity(String
The name of the Entity we wish to provide a value for.
name
)

NON-DOM Factory method; creates an Entity having this Document as its OwnerDoc.

public EntityReference
createEntityReference(String
The name of the Entity we wish to refer to
name
)

Implements org.w3c.dom.Document.createEntityReference.

Factory method; creates an EntityReference having this Document as its OwnerDoc.

public Notation
createNotation(String
The name of the Notation we wish to describe
name
)

NON-DOM Factory method; creates a Notation having this Document as its OwnerDoc.

public ProcessingInstruction
createProcessingInstruction(String
The target "processor channel"
target
,
String
Parameter string to be passed to the target.
data
)

Implements org.w3c.dom.Document.createProcessingInstruction.

Factory method; creates a ProcessingInstruction having this Document as its OwnerDoc.

public Text
createTextNode(String
The initial contents of the Text.
data
)

Implements org.w3c.dom.Document.createTextNode.

Factory method; creates a Text node having this Document as its OwnerDoc.

pack-priv void
deletedText(NodeImpl node, int offset, int count)

A method to be called when some text was deleted from a text node, so that live objects can be notified.

protected boolean
pack-priv void
freeNodeListCache(NodeListCache c)

Puts the given NodeListCache in the free list.

public boolean
getAsync()

DOM Level 3 WD - Experimental.

public String

Returns:

The absolute base URI of this node or null.
getBaseURI
()

Overrides com.sun.org.apache.xerces.internal.dom.NodeImpl.getBaseURI.

Implements org.w3c.dom.Node.getBaseURI.

Returns the absolute base URI of this node or null if the implementation wasn't able to obtain an absolute URI.

public DocumentType
getDoctype()

Implements org.w3c.dom.Document.getDoctype.

For XML, this provides access to the Document Type Definition.

public Element
getDocumentElement()

Implements org.w3c.dom.Document.getDocumentElement.

Convenience method, allowing direct access to the child node which is considered the root of the actual document content.

public String
getDocumentURI()

Implements org.w3c.dom.Document.getDocumentURI.

DOM Level 3 WD - Experimental.

public DOMConfiguration
getDomConfig()

Implements org.w3c.dom.Document.getDomConfig.

DOM Level 3 CR - Experimental The configuration used when Document.normalizeDocument is invoked.

public Element
getElementById(String
The unique id value for an element.
elementId
)

Implements org.w3c.dom.Document.getElementById.

Introduced in DOM Level 2 Returns the Element whose ID is given by elementId.

public NodeList
getElementsByTagName(String
The type of Element we want to gather. "*" will be taken as a wildcard, meaning "all elements in the document."
tagname
)

Implements org.w3c.dom.Document.getElementsByTagName.

Return a live collection of all descendent Elements (not just immediate children) having the specified tag name.

public NodeList

Returns:

NodeList A new NodeList object containing all the matched Elements.
getElementsByTagNameNS
(String
The namespace URI of the elements to match on. The special value "*" matches all namespaces. When it is null or an empty string, this method behaves like getElementsByTagName.
namespaceURI
,
String
The local name of the elements to match on. The special value "*" matches all local names.
localName
)

Implements org.w3c.dom.Document.getElementsByTagNameNS.

Introduced in DOM Level 2.

public String
getEncoding()
Deprecated This method is internal and only exists for compatibility with older applications. New applications should never call this method.

public boolean
getErrorChecking()

Returns true if the DOM implementation performs error checking.

public Object
getFeature(String
The name of the feature requested. Note that any plus sign "+" prepended to the name of the feature will be ignored since it is not significant in the context of this method.
feature
,
String
This is the version number of the feature to test.
version
)

Overrides com.sun.org.apache.xerces.internal.dom.NodeImpl.getFeature.

Implements org.w3c.dom.Node.getFeature.

This method returns a specialized object which implements the specialized APIs of the specified feature and version, as specified in .

public Element
getIdentifier(String idName)

Returns a previously registered element with the specified identifier name, or null if no element is registered.

public DOMImplementation
getImplementation()

Implements org.w3c.dom.Document.getImplementation.

Retrieve information describing the abilities of this particular DOM implementation.

public String
getInputEncoding()

Implements org.w3c.dom.Document.getInputEncoding.

DOM Level 3 CR - Experimental.

pack-priv boolean
getMutationEvents()

Returns true if the DOM implementation generates mutation events.

pack-priv NodeListCache
getNodeListCache(ParentNode owner)

Returns a NodeListCache for the given node.

public String
protected int
getNodeNumber()

Overrides com.sun.org.apache.xerces.internal.dom.NodeImpl.getNodeNumber.

NON-DOM: Get the number associated with this document.

protected int
getNodeNumber(Node node)

NON-DOM: Get a number associated with a node created with respect to this document.

public short
public final Document
public boolean
getStandalone()
Deprecated This method is internal and only exists for compatibility with older applications. New applications should never call this method.

public boolean
getStrictErrorChecking()

Implements org.w3c.dom.Document.getStrictErrorChecking.

An attribute specifying whether error checking is enforced or not.

public String
getTextContent()

Overrides com.sun.org.apache.xerces.internal.dom.ParentNode.getTextContent.

Implements org.w3c.dom.Node.getTextContent.

This attribute returns the text content of this node and its descendants.

public Object

Returns:

Returns the DOMObject associated to the given key on this node, or null if there was none.
getUserData
(Node
The node the object is associated to.
n
,
String
The key the object is associated to.
key
)

Retrieves the object associated to a key on a this node.

protected Object
getUserData(NodeImpl n)

NON-DOM: kept for backward compatibility Retreive user data related to a given node

protected Map<String, ParentNode.UserDataRecord>
public String
getVersion()
Deprecated This method is internal and only exists for compatibility with older applications. New applications should never call this method.

public String
getXmlEncoding()

Implements org.w3c.dom.Document.getXmlEncoding.

DOM Level 3 WD - Experimental.

public boolean
getXmlStandalone()

Implements org.w3c.dom.Document.getXmlStandalone.

DOM Level 3 WD - Experimental.

public String
getXmlVersion()

Implements org.w3c.dom.Document.getXmlVersion.

DOM Level 3 WD - Experimental.

public Node
importNode(Node
The node to import.
source
,
boolean
If true, recursively import the subtree under the specified node; if false, import only the node itself, as explained above. This has no effect on nodes that cannot have any children, and on Attr, and EntityReference nodes.
deep
)

Implements org.w3c.dom.Document.importNode.

Copies a node from another document to this document.

private Node
importNode(Node source, boolean deep, boolean cloningDoc, Map<Node, String> reversedIdentifiers)

Overloaded implementation of DOM's importNode method.

public Node
insertBefore(Node
The node to insert.
newChild
,
Node
The reference node, i.e., the node before which the new node must be inserted.
refChild
)

Overrides com.sun.org.apache.xerces.internal.dom.ParentNode.insertBefore.

Implements org.w3c.dom.Node.insertBefore.

Since a Document may contain at most one top-level Element child, and at most one DocumentType declaraction, we need to subclass our add-children methods to implement this constraint.

pack-priv void
insertedNode(NodeImpl node, NodeImpl newInternal, boolean replace)

A method to be called when a node has been inserted in the tree.

pack-priv void
insertedText(NodeImpl node, int offset, int count)

A method to be called when some text was inserted into a text node, so that live objects can be notified.

pack-priv void
insertingNode(NodeImpl node, boolean replace)

A method to be called when a node is about to be inserted in the tree.

protected boolean
isKidOK(Node parent, Node child)

Uses the kidOK lookup table to check whether the proposed tree structure is legal.

pack-priv boolean
public static final boolean
isValidQName(String
prefix of qualified name
prefix
,
String
local part of qualified name
local
,
boolean xml11Version)

Checks if the given qualified name is legal with respect to the version of XML to which this document must conform.

pack-priv boolean
isXML11Version()

We could have more xml versions in future , but for now we could do with this to handle XML 1.0 and 1.1

public static final boolean
isXMLName(String s, boolean xml11Version)

Check the string against XML's definition of acceptable names for elements and attributes and so on using the XMLCharacterProperties utility class

pack-priv boolean
public boolean

Returns:

If async is set to true load returns true if the document load was successfully initiated. If an error occurred when initiating the document load, load returns false.If async is set to false load returns true if the document was successfully loaded and parsed. If an error occurred when either loading or parsing the URI, load returns false.
load
(String
The URI reference for the XML file to be loaded. If this is a relative URI, the base URI used by the implementation is implementation dependent.
uri
)

DOM Level 3 WD - Experimental.

public boolean

Returns:

true if parsing the input string succeeded without errors, otherwise false.
loadXML
(String
A string containing an XML document.
source
)

DOM Level 3 WD - Experimental.

pack-priv void
modifiedAttrValue(AttrImpl attr, String oldvalue)

A method to be called when an attribute value has been modified

pack-priv void
modifiedCharacterData(NodeImpl node, String oldvalue, String value, boolean replace)

A method to be called when a character data node has been modified

pack-priv void
modifyingCharacterData(NodeImpl node, boolean replace)

A method to be called when a character data node is about to be modified

public void
normalizeDocument()

Implements org.w3c.dom.Document.normalizeDocument.

DOM Level 3 WD - Experimental Normalize document.

public void
putIdentifier(String idName, Element element)

Registers an identifier name with a specified element node.

private void
public Node
removeChild(Node
The node being removed.
oldChild
)

Overrides com.sun.org.apache.xerces.internal.dom.ParentNode.removeChild.

Implements org.w3c.dom.Node.removeChild.

Since insertBefore caches the docElement (and, currently, docType), removeChild has to know how to undo the cache

Revisit

According to the spec it is not allowed to alter neither the document element nor the document type in any way

pack-priv void
removedAttrNode(AttrImpl attr, NodeImpl oldOwner, String name)

A method to be called when an attribute node has been removed

pack-priv void
removedNode(NodeImpl node, boolean replace)

A method to be called when a node has been removed from the tree.

protected void
removeEventListener(NodeImpl node, String type, EventListener listener, boolean useCapture)

public void
removeIdentifier(String idName)

Removes a previously registered element with the specified identifier name.

pack-priv Map<String, ParentNode.UserDataRecord>

Returns:

The removed table.
removeUserDataTable
(Node
The node this operation applies to.
n
)

Remove user data table for the given node.

pack-priv void
removingNode(NodeImpl node, NodeImpl oldChild, boolean replace)

A method to be called when a node is about to be removed from the tree.

pack-priv void
renamedAttrNode(Attr oldAt, Attr newAt)

A method to be called when an attribute node has been renamed

pack-priv void
renamedElement(Element oldEl, Element newEl)

A method to be called when an element has been renamed

public Node
renameNode(Node
The node to rename.
n
,
String
The new namespace URI.
namespaceURI
,
String
The new qualified name.
name
)

Implements org.w3c.dom.Document.renameNode.

DOM Level 3 WD - Experimental.

public Node
replaceChild(Node
The new node to put in the child list.
newChild
,
Node
The node being replaced in the list.
oldChild
)

Overrides com.sun.org.apache.xerces.internal.dom.ParentNode.replaceChild.

Implements org.w3c.dom.Node.replaceChild.

Since we cache the docElement (and, currently, docType), replaceChild has to update the cache

Revisit

According to the spec it is not allowed to alter neither the document element nor the document type in any way

pack-priv void
replacedCharacterData(NodeImpl node, String oldvalue, String value)

method to be called when a character data node has been replaced.

pack-priv void
replacedNode(NodeImpl node)

A method to be called when a node has been replaced in the tree.

pack-priv void
replacedText(NodeImpl node)

A method to be called when some text was changed in a text node, so that live objects can be notified.

pack-priv void
replacingData(NodeImpl node)

A method to be called when a character data node is about to be replaced

pack-priv void
replacingNode(NodeImpl node)

A method to be called when a node is about to be replaced in the tree.

public String

Returns:

The serialized document or null in case an error occurred.
saveXML
(Node
Specifies what to serialize, if this parameter is null the whole document is serialized, if it's non-null the given node is serialized.
node
)

DOM Level 3 WD - Experimental.

public void
setAsync(boolean async)

DOM Level 3 WD - Experimental.

pack-priv void
setAttrNode(AttrImpl attr, AttrImpl previous)

A method to be called when an attribute node has been set

public void
setDocumentURI(String documentURI)

Implements org.w3c.dom.Document.setDocumentURI.

DOM Level 3 WD - Experimental.

public void
setEncoding(String value)
Deprecated This method is internal and only exists for compatibility with older applications. New applications should never call this method.

public void
setErrorChecking(boolean check)

Sets whether the DOM implementation performs error checking upon operations.

public void
setInputEncoding(String value)

DOM Internal (Was a DOM L3 Core WD public interface method setActualEncoding ) An attribute specifying the actual encoding of this document.

pack-priv void
setMutationEvents(boolean set)

Sets whether the DOM implementation generates mutation events upon operations.

public void
setStandalone(boolean value)
Deprecated This method is internal and only exists for compatibility with older applications. New applications should never call this method.

public void
setStrictErrorChecking(boolean check)

Implements org.w3c.dom.Document.setStrictErrorChecking.

An attribute specifying whether error checking is enforced or not.

public void
setTextContent(String textContent)

Overrides com.sun.org.apache.xerces.internal.dom.ParentNode.setTextContent.

Implements org.w3c.dom.Node.setTextContent.

This attribute returns the text content of this node and its descendants.

public Object

Returns:

Returns the DOMObject previously associated to the given key on this node, or null if there was none.
setUserData
(Node
The node to associate the object to.
n
,
String
The key to associate the object to.
key
,
Object
The object to associate to the given key, or null to remove any existing association to that key.
data
,
UserDataHandler
The handler to associate to that key, or null.
handler
)

Associate an object to a key on this node.

protected void
setUserData(NodeImpl n, Object data)

NON-DOM: kept for backward compatibility Store user data related to a given node This is a place where we could use weak references!

pack-priv void
setUserDataTable(Node
The node this operation applies to.
n
,
Map<String, ParentNode.UserDataRecord>
The user data table.
data
)

Set user data table for the given node.

public void
setVersion(String value)
Deprecated This method is internal and only exists for compatibility with older applications. New applications should never call this method.

public void
setXmlEncoding(String value)

DOM Internal (Was a DOM L3 Core WD public interface method setXMLEncoding ) An attribute specifying, as part of the XML declaration, the encoding of this document.

public void
setXmlStandalone(boolean value)

Implements org.w3c.dom.Document.setXmlStandalone.

DOM Level 3 CR - Experimental.

public void
setXmlVersion(String value)

Implements org.w3c.dom.Document.setXmlVersion.

DOM Level 3 CR - Experimental.

protected void
undeferChildren(Node node)

Traverses the DOM Tree and expands deferred nodes and their children.

private void
Inherited from com.sun.org.apache.xerces.internal.dom.ParentNode:
checkNormalizationAfterInsertcheckNormalizationAfterRemovegetChildNodesgetChildNodesUnoptimizedgetFirstChildgetLastChildgetLengthgetTextContenthasChildNodeshasTextContentinternalInsertBeforeinternalRemoveChildisEqualNodeitemlastChildlastChildnormalizeownerDocumentsetOwnerDocumentsetReadOnlysynchronizeChildren