|
XML for Java EA2 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ibm.xml.dom.NodeImpl | +--com.ibm.xml.dom.DocumentImpl
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 DocumentImpl class also implements the DOM Level 2 DocumentTraversal interface. This interface is comprised of factory methods needed to create NodeIterators and TreeWalkers. The process of creating these traversal objects also adds these references to this document. After finishing with the It is important to remove the traversal objects using the remove methods in this implementation. This allows the release of all the references from the traversal objects to the DOM Nodes.
Note: When any node in the document is serialized, the entire document is serialized along with it.
Field Summary | |
protected boolean |
allowGrammarAccess
Allow grammar access. |
protected ElementImpl |
docElement
Document element. |
protected DocumentTypeImpl |
docType
Document type. |
protected java.util.Hashtable |
identifiers
Identifiers. |
protected java.util.Vector |
iterators
Iterators |
protected java.util.Vector |
treeWalkers
Tree walkers |
Fields inherited from class com.ibm.xml.dom.NodeImpl |
ELEMENT_DEFINITION_NODE,
firstChild,
kidOK,
lastChild,
name,
nextSibling,
ownerDocument,
parentNode,
previousSibling,
readOnly,
syncChildren,
syncData,
userData,
value |
Constructor Summary | |
DocumentImpl()
NON-DOM: Actually creating a Document is outside the DOM's spec, since it has to operate in terms of a particular implementation. |
|
DocumentImpl(boolean grammarAccess)
Experimental constructor. |
|
DocumentImpl(DocumentType doctype)
|
|
DocumentImpl(DocumentType doctype,
boolean grammarAccess)
Experimental constructor. |
Method Summary | |
Node |
cloneNode(boolean deep)
Deep-clone a document, including fixing ownerDoc for the cloned children. |
Attr |
createAttribute(java.lang.String name)
Factory method; creates an Attribute having this Document as its OwnerDoc. |
Attr |
createAttributeNS(java.lang.String namespaceURI,
java.lang.String qualifiedName)
Introduced in DOM Level 2. |
CDATASection |
createCDATASection(java.lang.String data)
Factory method; creates a CDATASection having this Document as its OwnerDoc. |
Comment |
createComment(java.lang.String data)
Factory method; creates a Comment having this Document as its OwnerDoc. |
DocumentFragment |
createDocumentFragment()
Factory method; creates a DocumentFragment having this Document as its OwnerDoc. |
DocumentType |
createDocumentType(java.lang.String qualifiedName,
java.lang.String publicID,
java.lang.String systemID)
NON-DOM Factory method; creates a DocumentType having this Document as its OwnerDoc. |
Element |
createElement(java.lang.String tagName)
Factory method; creates an Element having this Document as its OwnerDoc. |
ElementDefinitionImpl |
createElementDefinition(java.lang.String name)
NON-DOM Factory method: creates an element definition. |
Element |
createElementNS(java.lang.String namespaceURI,
java.lang.String qualifiedName)
Introduced in DOM Level 2. |
Entity |
createEntity(java.lang.String name)
NON-DOM Factory method; creates an Entity having this Document as its OwnerDoc. |
EntityReference |
createEntityReference(java.lang.String name)
Factory method; creates an EntityReference having this Document as its OwnerDoc. |
NodeIterator |
createNodeIterator(Node root,
short whatToShow,
NodeFilter filter)
Introduced in DOM Level 2. |
Notation |
createNotation(java.lang.String name)
NON-DOM Factory method; creates a Notation having this Document as its OwnerDoc. |
ProcessingInstruction |
createProcessingInstruction(java.lang.String target,
java.lang.String data)
Factory method; creates a ProcessingInstruction having this Document as its OwnerDoc. |
Text |
createTextNode(java.lang.String data)
Factory method; creates a Text node having this Document as its OwnerDoc. |
TreeWalker |
createTreeWalker(Node root,
short whatToShow,
NodeFilter filter)
Introduced in DOM Level 2. |
DocumentType |
getDoctype()
For XML, this provides access to the Document Type Definition. |
Element |
getDocumentElement()
Convenience method, allowing direct access to the child node which is considered the root of the actual document content. |
NodeList |
getElementsByTagName(java.lang.String tagname)
Return a live collection of all descendent Elements (not just immediate children) having the specified tag name. |
NodeList |
getElementsByTagNameNS(java.lang.String namespaceURI,
java.lang.String localName)
Introduced in DOM Level 2. |
Element |
getIdentifier(java.lang.String idName)
Returns a previously registered element with the specified identifier name, or null if no element is registered. |
java.util.Enumeration |
getIdentifiers()
Returns an enumeration registered of identifier names. |
DOMImplementation |
getImplementation()
Retrieve information describing the abilities of this particular DOM implementation. |
java.util.Enumeration |
getNodeIterators()
Return an Enumeration of all NodeIterators. |
java.lang.String |
getNodeName()
Returns the node name. |
short |
getNodeType()
Returns the node type. |
java.lang.String |
getNodeValue()
Returns the node value. |
java.util.Enumeration |
getTreeWalkers()
Return an Enumeration of all TreeWalkers. |
Node |
importNode(Node source,
boolean deep)
NON-DOM: Copies data from the source node. |
Node |
insertBefore(Node newChild,
Node refChild)
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. |
protected boolean |
isKidOK(Node parent,
Node child)
Uses the kidOK lookup table to check whether the proposed tree structure is legal. |
static boolean |
isXMLName(java.lang.String s)
Check the string against XML's definition of acceptable names for elements and attributes and so on. |
void |
putIdentifier(java.lang.String idName,
Element element)
Registers an identifier name with a specified element node. |
Node |
removeChild(Node oldChild)
Since insertBefore caches the docElement (and, currently, docType), removeChild has to know how to undo the cache |
void |
removeIdentifier(java.lang.String idName)
Removes a previously registered element with the specified identifier name. |
void |
removeNodeIterator(NodeIterator nodeIterator)
Remove a NodeIterator from the list of NodeIterators. |
void |
removeNodeIterators()
Remove all NodeIterators from the list of NodeIterators |
void |
removeTreeWalker(TreeWalker treeWalker)
Remove a TreeWalker from the list of TreeWalkers. |
void |
removeTreeWalkers()
Remove all TreeWalkers from the list of TreeWalkers |
void |
setNodeValue(java.lang.String x)
Documents never have a nodeValue. |
Methods inherited from class com.ibm.xml.dom.NodeImpl |
appendChild,
changed,
getAttributes,
getChildNodes,
getFirstChild,
getLastChild,
getLength,
getLocalName,
getNamespaceURI,
getNextSibling,
getOwnerDocument,
getParentNode,
getPrefix,
getPreviousSibling,
getReadOnly,
getUserData,
hasChildNodes,
item,
replaceChild,
setPrefix,
setReadOnly,
setUserData,
supports,
synchronizeChildren,
synchronizeData,
toString |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
protected DocumentTypeImpl docType
protected ElementImpl docElement
protected java.util.Hashtable identifiers
protected java.util.Vector iterators
protected java.util.Vector treeWalkers
protected boolean allowGrammarAccess
Constructor Detail |
public DocumentImpl()
public DocumentImpl(boolean grammarAccess)
public DocumentImpl(DocumentType doctype)
public DocumentImpl(DocumentType doctype, boolean grammarAccess)
Method Detail |
public short getNodeType()
public java.lang.String getNodeName()
public java.lang.String getNodeValue()
public Node cloneNode(boolean deep)
deep
- boolean, iff true replicate childrenpublic Node insertBefore(Node newChild, Node refChild) throws DOMException
While I'm doing so, I've taken advantage of the opportunity to cache documentElement and docType so we don't have to search for them.
public Node removeChild(Node oldChild) throws DOMException
public void setNodeValue(java.lang.String x) throws DOMException
public Attr createAttribute(java.lang.String name) throws DOMException
name
- The name of the attribute. Note that the attribute's value
is _not_ established at the factory; remember to set it!public CDATASection createCDATASection(java.lang.String data) throws DOMException
data
- The initial contents of the CDATApublic Comment createComment(java.lang.String data)
data
- The initial contents of the Comment.public DocumentFragment createDocumentFragment()
public Element createElement(java.lang.String tagName) throws DOMException
tagName
- 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.public EntityReference createEntityReference(java.lang.String name) throws DOMException
name
- The name of the Entity we wish to refer topublic ProcessingInstruction createProcessingInstruction(java.lang.String target, java.lang.String data) throws DOMException
target
- The target "processor channel"data
- Parameter string to be passed to the target.public Text createTextNode(java.lang.String data)
data
- The initial contents of the Text.public DocumentType getDoctype()
public Element getDocumentElement()
public NodeList getElementsByTagName(java.lang.String tagname)
tagname
- The type of Element we want to gather. "*" will be
taken as a wildcard, meaning "all elements in the document."com.ibm.domimpl.DeepNodeListImpl
public DOMImplementation getImplementation()
public DocumentType createDocumentType(java.lang.String qualifiedName, java.lang.String publicID, java.lang.String systemID) throws DOMException
name
- The name of the Entity we wish to provide a value for.public Entity createEntity(java.lang.String name) throws DOMException
name
- The name of the Entity we wish to provide a value for.public Notation createNotation(java.lang.String name) throws DOMException
name
- The name of the Notation we wish to describepublic ElementDefinitionImpl createElementDefinition(java.lang.String name) throws DOMException
public Node importNode(Node source, boolean deep) throws DOMException
public void putIdentifier(java.lang.String idName, Element element)
getIdentifier(java.lang.String)
,
removeIdentifier(java.lang.String)
public Element getIdentifier(java.lang.String idName)
putIdentifier(java.lang.String, org.w3c.dom.Element)
,
removeIdentifier(java.lang.String)
public void removeIdentifier(java.lang.String idName)
putIdentifier(java.lang.String, org.w3c.dom.Element)
,
getIdentifier(java.lang.String)
public java.util.Enumeration getIdentifiers()
public Element createElementNS(java.lang.String namespaceURI, java.lang.String qualifiedName) throws DOMException
Creates an element of the given qualified name and namespace URI.
namespaceURI
- The namespace URI of the element to
create. When it is null or an empty string,
this method behaves like createElement.qualifiedName
- The qualified name of the element type to
instantiate.public Attr createAttributeNS(java.lang.String namespaceURI, java.lang.String qualifiedName) throws DOMException
Creates an attribute of the given qualified name and namespace URI.
namespaceURI
- The namespace URI of the attribute to
create. When it is null or an empty string,
this method behaves like createAttribute.qualifiedName
- The qualified name of the attribute to
instantiate.public NodeList getElementsByTagNameNS(java.lang.String namespaceURI, java.lang.String localName)
Returns a NodeList of all the Elements with a given local name and namespace URI in the order in which they would be encountered in a preorder traversal of the Document tree.
namespaceURI
- 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.localName
- The local name of the elements to match on.
The special value "*" matches all local names.public NodeIterator createNodeIterator(Node root, short whatToShow, NodeFilter filter)
Create and return a NodeIterator. The NodeIterator is added to a list of NodeIterators so that it can be removed to free up the DOM Nodes it references.
root
- The root of the iterator.whatToShow
- The whatToShow mask.filter
- The NodeFilter installed. Null means no filter.removeNodeIterator(com.ibm.xml.domx.traversal.NodeIterator)
,
removeNodeIterators()
,
getNodeIterators()
public TreeWalker createTreeWalker(Node root, short whatToShow, NodeFilter filter)
Create and return a TreeWalker. The TreeWalker is added to a list of TreeWalkers so that it can be removed to free up the DOM Nodes it references.
root
- The root of the iterator.whatToShow
- The whatToShow mask.filter
- The NodeFilter installed. Null means no filter.removeTreeWalker(com.ibm.xml.domx.traversal.TreeWalker)
,
removeTreeWalkers()
,
getTreeWalkers()
public void removeNodeIterator(NodeIterator nodeIterator)
public void removeTreeWalker(TreeWalker treeWalker)
public java.util.Enumeration getNodeIterators()
public java.util.Enumeration getTreeWalkers()
public void removeNodeIterators()
public void removeTreeWalkers()
public static boolean isXMLName(java.lang.String s)
[Definition:] A Name is a token beginning with a letter or one of a few punctuation characters, and continuing with letters, digits, hyphens,underscores, colons, or full stops, together known as name characters.
Unfortunately, that spec goes on to say that after the first character, names may use "combining characters" and "extender characters", which are explicitly listed rather than defined in terms of Java's Unicode character types... and which in fact can't be expressed solely in terms of those types.
I've empirically derived some tests which are partly based on the Java Unicode space (which simplifies them considerably), but they still wind up having to be further qualified. This may not remain valid if future extensions of Java and/or Unicode introduce other characters having these type numbers.
Suggestions for alternative implementations would be welcome.
protected boolean isKidOK(Node parent, Node child)
|
XML for Java EA2 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |