gnu.xml.dom
Class DomDocument

java.lang.Object
  extended bygnu.xml.dom.DomNode
      extended bygnu.xml.dom.DomDocument
All Implemented Interfaces:
java.lang.Cloneable, org.w3c.dom.Document, org.w3c.dom.events.DocumentEvent, org.w3c.dom.traversal.DocumentTraversal, org.w3c.dom.events.EventTarget, org.w3c.dom.Node, org.w3c.dom.NodeList

public class DomDocument
extends DomNode
implements org.w3c.dom.Document, org.w3c.dom.traversal.DocumentTraversal

"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.)

Version:
$Date: 2001/11/20 04:53:46 $
Author:
David Brownell

Field Summary
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, 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.
protected DomDocument(org.w3c.dom.DOMImplementation impl)
          Constructs a Document node, associating it with the specified implementation.
 
Method Summary
 org.w3c.dom.Node appendChild(org.w3c.dom.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.
 org.w3c.dom.Attr createAttribute(java.lang.String name)
          DOM L1 Returns a newly created attribute with the specified name.
 org.w3c.dom.Attr createAttributeNS(java.lang.String namespaceURI, java.lang.String name)
          DOM L2 Returns a newly created attribute with the specified name and namespace information.
 org.w3c.dom.CDATASection createCDATASection(char[] buf, int off, int len)
          Returns a newly created CDATA section node with the specified value.
 org.w3c.dom.CDATASection createCDATASection(java.lang.String value)
          DOM L1 Returns a newly created CDATA section node with the specified value.
 org.w3c.dom.Comment createComment(java.lang.String value)
          DOM L1 Returns a newly created comment node with the specified value.
 org.w3c.dom.DocumentFragment createDocumentFragment()
          DOM L1 Returns a newly created document fragment.
 org.w3c.dom.Element createElement(java.lang.String name)
          DOM L1 Returns a newly created element with the specified name.
 org.w3c.dom.Element createElementNS(java.lang.String namespaceURI, java.lang.String name)
          DOM L2 Returns a newly created element with the specified name and namespace information.
 org.w3c.dom.EntityReference createEntityReference(java.lang.String name)
          DOM L1 Returns a newly created reference to the specified entity.
 org.w3c.dom.traversal.NodeIterator createNodeIterator(org.w3c.dom.Node root, int whatToShow, org.w3c.dom.traversal.NodeFilter filter, boolean expandEntities)
          DOM L2 (Traversal) Returns a newly created node iterator.
 org.w3c.dom.ProcessingInstruction createProcessingInstruction(java.lang.String target, java.lang.String data)
          DOM L1 Returns a newly created processing instruction.
 org.w3c.dom.Text createTextNode(char[] buf, int off, int len)
          Returns a newly created text node with the specified value.
 org.w3c.dom.Text createTextNode(java.lang.String value)
          DOM L1 Returns a newly created text node with the specified value.
 org.w3c.dom.traversal.TreeWalker createTreeWalker(org.w3c.dom.Node root, int whatToShow, org.w3c.dom.traversal.NodeFilter filter, boolean entityReferenceExpansion)
           
 org.w3c.dom.DocumentType getDoctype()
          DOM L1 Returns the document's DocumentType, or null.
 org.w3c.dom.Element getDocumentElement()
          DOM L1 Returns the document's root element, or null.
 org.w3c.dom.Element getElementById(java.lang.String id)
          DOM L1 (relocated in DOM L2) Returns the element with the specified "ID" attribute, or null.
 org.w3c.dom.DOMImplementation getImplementation()
          DOM L1 Returns the document's DOMImplementation.
 java.lang.String getNodeName()
          DOM L1 Returns the constant "#document".
 short getNodeType()
          DOM L1 Returns the constant DOCUMENT_NODE.
 org.w3c.dom.Node importNode(org.w3c.dom.Node copiedNode, boolean deep)
          DOM L2 Makes a copy of the specified node, with all nodes "owned" by this document and with children optionally copied.
 org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.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 isCheckingCharacters()
          Returns true if certain expensive checks are performed.
 org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.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 setCheckingCharacters(boolean value)
          Controls whether certain expensive checks, duplicating those that conformant XML parsers must perform, are made.
static void verifyXmlName(java.lang.String name)
          Throws a DOM exception if the specified name is not a legal XML 1.0 name.
 
Methods inherited from class gnu.xml.dom.DomNode
addEventListener, clone, cloneNode, compact, createEvent, dispatchEvent, getAttributes, getChildNodes, getElementsByTagName, getElementsByTagNameNS, getFirstChild, getLastChild, getLength, getLocalName, getNamespaceURI, getNextSibling, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, hasAttributes, hasChildNodes, isReadonly, isSupported, item, makeReadonly, nameAndTypeEquals, normalize, removeChild, removeEventListener, setNodeValue, setPrefix, trimToSize
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.w3c.dom.Document
getElementsByTagName, getElementsByTagNameNS
 
Methods inherited from interface org.w3c.dom.Node
cloneNode, getAttributes, getChildNodes, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, hasAttributes, hasChildNodes, isSupported, normalize, removeChild, setNodeValue, setPrefix
 

Constructor Detail

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.

See Also:
setCheckingCharacters(boolean)

DomDocument

protected DomDocument(org.w3c.dom.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.

See Also:
DomImpl, setCheckingCharacters(boolean)
Method Detail

getNodeName

public final java.lang.String getNodeName()
DOM L1 Returns the constant "#document".

Specified by:
getNodeName in interface org.w3c.dom.Node

getNodeType

public final short getNodeType()
DOM L1 Returns the constant DOCUMENT_NODE.

Specified by:
getNodeType in interface org.w3c.dom.Node

getDocumentElement

public final org.w3c.dom.Element getDocumentElement()
DOM L1 Returns the document's root element, or null.

Specified by:
getDocumentElement in interface org.w3c.dom.Document

getDoctype

public final org.w3c.dom.DocumentType getDoctype()
DOM L1 Returns the document's DocumentType, or null.

Specified by:
getDoctype in interface org.w3c.dom.Document

getImplementation

public final org.w3c.dom.DOMImplementation getImplementation()
DOM L1 Returns the document's DOMImplementation.

Specified by:
getImplementation in interface org.w3c.dom.Document

getElementById

public org.w3c.dom.Element getElementById(java.lang.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 org.w3c.dom.Document

appendChild

public org.w3c.dom.Node appendChild(org.w3c.dom.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 org.w3c.dom.Node
Overrides:
appendChild in class DomNode

insertBefore

public org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild,
                                     org.w3c.dom.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 org.w3c.dom.Node
Overrides:
insertBefore in class DomNode

replaceChild

public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild,
                                     org.w3c.dom.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 org.w3c.dom.Node
Overrides:
replaceChild in class DomNode

verifyXmlName

public static void verifyXmlName(java.lang.String name)
Throws a DOM exception if the specified name is not a legal XML 1.0 name. Actually this uses a very similar set of rules, closer to Unicode rules than to the rules encoded in the large table at the end of the XML 1.0 specification.

Throws:
DomException - INVALID_CHARACTER_ERR if the name isn't legal as an XML name.

setCheckingCharacters

public final void setCheckingCharacters(boolean value)
Controls whether certain expensive checks, duplicating those that conformant XML parsers must perform, are made.


isCheckingCharacters

public final boolean isCheckingCharacters()
Returns true if certain expensive checks are performed. Those checks are intended to reject illegal names, and characters that are illegal as XML characters.


createElement

public org.w3c.dom.Element createElement(java.lang.String name)
DOM L1 Returns a newly created element with the specified name.

Specified by:
createElement in interface org.w3c.dom.Document

createElementNS

public org.w3c.dom.Element createElementNS(java.lang.String namespaceURI,
                                           java.lang.String name)
DOM L2 Returns a newly created element with the specified name and namespace information.

Specified by:
createElementNS in interface org.w3c.dom.Document

createDocumentFragment

public org.w3c.dom.DocumentFragment createDocumentFragment()
DOM L1 Returns a newly created document fragment.

Specified by:
createDocumentFragment in interface org.w3c.dom.Document

createTextNode

public org.w3c.dom.Text createTextNode(java.lang.String value)
DOM L1 Returns a newly created text node with the specified value.

Specified by:
createTextNode in interface org.w3c.dom.Document

createTextNode

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


createComment

public org.w3c.dom.Comment createComment(java.lang.String value)
DOM L1 Returns a newly created comment node with the specified value.

Specified by:
createComment in interface org.w3c.dom.Document

createCDATASection

public org.w3c.dom.CDATASection createCDATASection(java.lang.String value)
DOM L1 Returns a newly created CDATA section node with the specified value.

Specified by:
createCDATASection in interface org.w3c.dom.Document

createCDATASection

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


createProcessingInstruction

public org.w3c.dom.ProcessingInstruction createProcessingInstruction(java.lang.String target,
                                                                     java.lang.String data)
DOM L1 Returns a newly created processing instruction.

Specified by:
createProcessingInstruction in interface org.w3c.dom.Document

createAttribute

public org.w3c.dom.Attr createAttribute(java.lang.String name)
DOM L1 Returns a newly created attribute with the specified name.

Specified by:
createAttribute in interface org.w3c.dom.Document

createAttributeNS

public org.w3c.dom.Attr createAttributeNS(java.lang.String namespaceURI,
                                          java.lang.String name)
DOM L2 Returns a newly created attribute with the specified name and namespace information.

Specified by:
createAttributeNS in interface org.w3c.dom.Document

createEntityReference

public org.w3c.dom.EntityReference createEntityReference(java.lang.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 org.w3c.dom.Document
See Also:
DomNode.makeReadonly()

importNode

public org.w3c.dom.Node importNode(org.w3c.dom.Node copiedNode,
                                   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 org.w3c.dom.Document

createNodeIterator

public org.w3c.dom.traversal.NodeIterator createNodeIterator(org.w3c.dom.Node root,
                                                             int whatToShow,
                                                             org.w3c.dom.traversal.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 org.w3c.dom.traversal.DocumentTraversal
See Also:
DomIterator

createTreeWalker

public org.w3c.dom.traversal.TreeWalker createTreeWalker(org.w3c.dom.Node root,
                                                         int whatToShow,
                                                         org.w3c.dom.traversal.NodeFilter filter,
                                                         boolean entityReferenceExpansion)
Specified by:
createTreeWalker in interface org.w3c.dom.traversal.DocumentTraversal


Source code is under GPL (with library exception) in the JAXP project at http://www.gnu.org/software/classpathx/jaxp
This documentation was derived from that source code on 2008-10-18.