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)
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)
XPathNSResolver
createNSResolver(Node nodeResolver)
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)
Object
evaluate(String expression, Node contextNode, XPathNSResolver resolver, short type, Object result)
String
getBaseURI()
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()
DOMConfiguration
getDomConfig()
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()
String
getXmlEncoding()
DOM L3
boolean
getXmlStandalone()
String
getXmlVersion()
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)
boolean
isEqualNode(Node arg)
String
lookupNamespaceURI(String prefix)
String
lookupPrefix(String namespaceURI)
void
normalizeDocument()
Node
renameNode(Node n, String namespaceURI, String qualifiedName)
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)
void
setInputEncoding(String inputEncoding)
void
setStrictErrorChecking(boolean strictErrorChecking)
void
setXmlEncoding(String encoding)
void
setXmlStandalone(boolean xmlStandalone)
void
setXmlVersion(String xmlVersion)
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)
Specified by:
adoptNode in interface Document

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
Specified by:
createExpression in interface XPathEvaluator

createNSResolver

public XPathNSResolver createNSResolver(Node nodeResolver)
Specified by:
createNSResolver in interface XPathEvaluator

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)
Specified by:
createTreeWalker in interface DocumentTraversal

evaluate

public Object evaluate(String expression,
                       Node contextNode,
                       XPathNSResolver resolver,
                       short type,
                       Object result)
            throws XPathException,
                   DOMException
Specified by:
evaluate in interface XPathEvaluator

getBaseURI

public String getBaseURI()
Specified by:
getBaseURI in interface Node
Overrides:
getBaseURI in interface DomNode

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()
Specified by:
getDocumentURI in interface Document

getDomConfig

public DOMConfiguration getDomConfig()
Specified by:
getDomConfig in interface Document

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()
Specified by:
getStrictErrorChecking in interface Document

getXmlEncoding

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

getXmlStandalone

public boolean getXmlStandalone()
Specified by:
getXmlStandalone in interface Document

getXmlVersion

public String getXmlVersion()
Specified by:
getXmlVersion in interface Document

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)
Specified by:
isDefaultNamespace in interface Node
Overrides:
isDefaultNamespace in interface DomNode

isEqualNode

public boolean isEqualNode(Node arg)
Specified by:
isEqualNode in interface Node
Overrides:
isEqualNode in interface DomNode

lookupNamespaceURI

public String lookupNamespaceURI(String prefix)
Specified by:
lookupNamespaceURI in interface Node
Overrides:
lookupNamespaceURI in interface DomNode

lookupPrefix

public String lookupPrefix(String namespaceURI)
Specified by:
lookupPrefix in interface Node
Overrides:
lookupPrefix in interface DomNode

normalizeDocument

public void normalizeDocument()
Specified by:
normalizeDocument in interface Document

renameNode

public Node renameNode(Node n,
                       String namespaceURI,
                       String qualifiedName)
            throws DOMException
Specified by:
renameNode in interface Document

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)
Specified by:
setDocumentURI in interface Document

setInputEncoding

public void setInputEncoding(String inputEncoding)

setStrictErrorChecking

public void setStrictErrorChecking(boolean strictErrorChecking)
Specified by:
setStrictErrorChecking in interface Document

setXmlEncoding

public void setXmlEncoding(String encoding)

setXmlStandalone

public void setXmlStandalone(boolean xmlStandalone)
Specified by:
setXmlStandalone in interface Document

setXmlVersion

public void setXmlVersion(String xmlVersion)
Specified by:
setXmlVersion in interface Document

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.