gnu.xml.dom

Class DomDocument

public class DomDocument extends DomNode implements Document, 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

Constructor Summary
DomDocument()
Constructs a Document node, associating it with an instance of the DomImpl class.
protected DomDocument(DOMImplementation impl)
Constructs a Document node, associating it with the specified implementation.
Method Summary
NodeappendChild(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.
AttrcreateAttribute(String name)
DOM L1 Returns a newly created attribute with the specified name.
AttrcreateAttributeNS(String namespaceURI, String name)
DOM L2 Returns a newly created attribute with the specified name and namespace information.
CDATASectioncreateCDATASection(String value)
DOM L1 Returns a newly created CDATA section node with the specified value.
CDATASectioncreateCDATASection(char[] buf, int off, int len)
Returns a newly created CDATA section node with the specified value.
CommentcreateComment(String value)
DOM L1 Returns a newly created comment node with the specified value.
DocumentFragmentcreateDocumentFragment()
DOM L1 Returns a newly created document fragment.
ElementcreateElement(String name)
DOM L1 Returns a newly created element with the specified name.
ElementcreateElementNS(String namespaceURI, String name)
DOM L2 Returns a newly created element with the specified name and namespace information.
EntityReferencecreateEntityReference(String name)
DOM L1 Returns a newly created reference to the specified entity.
NodeIteratorcreateNodeIterator(Node root, int whatToShow, NodeFilter filter, boolean expandEntities)
DOM L2 (Traversal) Returns a newly created node iterator.
ProcessingInstructioncreateProcessingInstruction(String target, String data)
DOM L1 Returns a newly created processing instruction.
TextcreateTextNode(String value)
DOM L1 Returns a newly created text node with the specified value.
TextcreateTextNode(char[] buf, int off, int len)
Returns a newly created text node with the specified value.
TreeWalkercreateTreeWalker(Node root, int whatToShow, NodeFilter filter, boolean entityReferenceExpansion)
DocumentTypegetDoctype()
DOM L1 Returns the document's DocumentType, or null.
ElementgetDocumentElement()
DOM L1 Returns the document's root element, or null.
ElementgetElementById(String id)
DOM L1 (relocated in DOM L2) Returns the element with the specified "ID" attribute, or null.
DOMImplementationgetImplementation()
DOM L1 Returns the document's DOMImplementation.
StringgetNodeName()
DOM L1 Returns the constant "#document".
shortgetNodeType()
DOM L1 Returns the constant DOCUMENT_NODE.
NodeimportNode(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.
NodeinsertBefore(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.
booleanisCheckingCharacters()
Returns true if certain expensive checks are performed.
NodereplaceChild(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.
voidsetCheckingCharacters(boolean value)
Controls whether certain expensive checks, duplicating those that conformant XML parsers must perform, are made.
static voidverifyXmlName(String name)
Throws a DOM exception if the specified name is not a legal XML 1.0 name.

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: DomDocument

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.

See Also: DomImpl DomDocument

Method Detail

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.

createAttribute

public Attr createAttribute(String name)
DOM L1 Returns a newly created attribute with the specified name.

createAttributeNS

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

createCDATASection

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

createCDATASection

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

createComment

public Comment createComment(String value)
DOM L1 Returns a newly created comment node with the specified value.

createDocumentFragment

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

createElement

public Element createElement(String name)
DOM L1 Returns a newly created element with the specified name.

createElementNS

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

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.

See Also: DomNode

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!

See Also: DomIterator

createProcessingInstruction

public ProcessingInstruction createProcessingInstruction(String target, String data)
DOM L1 Returns a newly created processing instruction.

createTextNode

public Text createTextNode(String value)
DOM L1 Returns a newly created text node with the specified value.

createTextNode

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

createTreeWalker

public TreeWalker createTreeWalker(Node root, int whatToShow, NodeFilter filter, boolean entityReferenceExpansion)

getDoctype

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

getDocumentElement

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

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.

getImplementation

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

getNodeName

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

getNodeType

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

importNode

public Node importNode(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.

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.

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.

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.

setCheckingCharacters

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

verifyXmlName

public static void verifyXmlName(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.

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 2011-08-26.