com.sun.xml.tree
Class ElementNode

java.lang.Object
  |
  +--com.sun.xml.tree.NodeBase
        |
        +--com.sun.xml.tree.ParentNode
              |
              +--com.sun.xml.tree.ElementNode

public class ElementNode
extends com.sun.xml.tree.ParentNode
implements ElementEx

This class represents XML elements in a parse tree, and is often subclassed to add custom behaviors. When an XML Document object is built using an XmlDocumentBuilder instance, simple declarative configuration information may be used to control whether this class, or some specialized subclass (e.g. supporting HTML DOM methods) is used for elements in the resulting tree.

As well as defining new methods to provide behaviors which are specific to application frameworks, such as Servlets or Swing, such subclasses may also override methods such as doneParse and appendChild to perform some kinds of processing during tree construction. Such processing can include transforming tree structure to better suit the needs of a given application. When such transformation is done, the XmlWritable methods may need to be overridden to make elements transform themselves back to XML without losing information. (One common transformation is eliminating redundant representations of data; attributes of an XML element may correspond to defaultable object properties, and so on.)

Element nodes also support a single userObject property, which may be used to bind objects to elements where subclassing is either not possible or is inappropriate. For example, user interface objects often derive from java.awt.Component, so that they can't extend a different class (ElementNode).

See Also:
XmlDocumentBuilder

Constructor Summary
ElementNode()
          Partially constructs an element; its tag will be assigned by the factory (or subclass), while attributes and the parent (and implicitly, siblings) will assigned when it is joined to a DOM document.
 
Method Summary
 Node cloneNode(boolean deep)
          Creates a new unparented node whose attributes are the same as this node's attributes; if deep is true, the children of this node are cloned as children of the new node.
 java.lang.String getAttribute(java.lang.String name)
          DOM: Returns the value of the named attribute, or null
 java.lang.String getAttribute(java.lang.String uri, java.lang.String name)
           
 Attr getAttributeNode(java.lang.String name)
          DOM: returns the attribute
 Attr getAttributeNode(java.lang.String uri, java.lang.String name)
           
 NamedNodeMap getAttributes()
          DOM: Returns the attributes of this element.
 java.lang.String getIdAttributeName()
          Returns the name of the element's ID attribute, if one is known.
 java.lang.String getLocalName()
           
 java.lang.String getNamespace()
           
 java.lang.String getNodeName()
          DOM: Returns the name of the XML tag for this element.
 short getNodeType()
          DOM: Returns the ELEMENT_NODE node type.
 java.lang.String getTagName()
          DOM: Returns the name of the XML tag for this element.
 java.lang.Object getUserObject()
           
 void normalize()
          DOM: Merges all adjacent Text nodes in the tree rooted by this element.
 void removeAttribute(java.lang.String name)
          DOM: Remove the named attribute.
 Attr removeAttributeNode(Attr oldAttr)
          DOM: removes the attribute with the same name as this one
 void setAttribute(java.lang.String name, java.lang.String value)
          DOM: Assigns or modifies the value of the specified attribute.
 Attr setAttributeNode(Attr newAttr)
          DOM: assigns the attribute
 void setIdAttributeName(java.lang.String attName)
          Assigns the name of the element's ID attribute; only one attribute may have the ID type.
protected  void setTag(java.lang.String t)
          Assigns the element's tag, when the element has been constructed using the default constructor.
 void setUserObject(java.lang.Object userObject)
           
 java.lang.String toString()
          Returns the element and its content as a string, which includes all the markup embedded in this element.
 void trimToSize()
           
 void write(java.io.Writer out)
          Convenience method to construct a non-prettyprinting XML write context and call writeXml with it.
 void writeXml(XmlWriteContext context)
          Writes this element and all of its children out, as well formed XML.
 
Methods inherited from class com.sun.xml.tree.ParentNode
appendChild, doneChild, doneParse, getElementsByTagName, getFirstChild, getIndexOf, getLastChild, getLength, hasChildNodes, insertBefore, item, removeChild, replaceChild, startParse, writeChildrenXml
 
Methods inherited from class com.sun.xml.tree.NodeBase
getChildNodes, getInheritedAttribute, getInheritedAttribute, getLanguage, getNextSibling, getNodeValue, getOwnerDocument, getParentNode, getPreviousSibling, setNodeValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ElementNode

public ElementNode()
Partially constructs an element; its tag will be assigned by the factory (or subclass), while attributes and the parent (and implicitly, siblings) will assigned when it is joined to a DOM document.
Method Detail

trimToSize

public void trimToSize()
Specified by:
trimToSize in interface ElementEx
Overrides:
trimToSize in class com.sun.xml.tree.ParentNode

setTag

protected void setTag(java.lang.String t)
Assigns the element's tag, when the element has been constructed using the default constructor. For use by element factories potentially by custom subclasses.

getNamespace

public java.lang.String getNamespace()

getLocalName

public java.lang.String getLocalName()

getAttributes

public NamedNodeMap getAttributes()
DOM: Returns the attributes of this element.
Overrides:
getAttributes in class com.sun.xml.tree.NodeBase

toString

public java.lang.String toString()
Returns the element and its content as a string, which includes all the markup embedded in this element. If the element is not fully constructed, the content will not be an XML tag.
Overrides:
toString in class java.lang.Object

writeXml

public void writeXml(XmlWriteContext context)
              throws java.io.IOException
Writes this element and all of its children out, as well formed XML.

setIdAttributeName

public void setIdAttributeName(java.lang.String attName)
Assigns the name of the element's ID attribute; only one attribute may have the ID type. XML supports a kind of validatable internal linking using ID attributes, with IDREF attributes identifying specific nodes (and IDREFS attributes identifying sets of them).

getIdAttributeName

public java.lang.String getIdAttributeName()
Returns the name of the element's ID attribute, if one is known.
Specified by:
getIdAttributeName in interface ElementEx

setUserObject

public void setUserObject(java.lang.Object userObject)
Specified by:
setUserObject in interface ElementEx

getUserObject

public java.lang.Object getUserObject()
Specified by:
getUserObject in interface ElementEx

getNodeType

public short getNodeType()
DOM: Returns the ELEMENT_NODE node type.

getTagName

public java.lang.String getTagName()
DOM: Returns the name of the XML tag for this element.

getNodeName

public java.lang.String getNodeName()
DOM: Returns the name of the XML tag for this element.

getAttribute

public java.lang.String getAttribute(java.lang.String name)
DOM: Returns the value of the named attribute, or null

getAttribute

public java.lang.String getAttribute(java.lang.String uri,
                                     java.lang.String name)
Specified by:
getAttribute in interface ElementEx

getAttributeNode

public Attr getAttributeNode(java.lang.String uri,
                             java.lang.String name)
Specified by:
getAttributeNode in interface ElementEx

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String value)
                  throws DOMException
DOM: Assigns or modifies the value of the specified attribute.

removeAttribute

public void removeAttribute(java.lang.String name)
                     throws DOMException
DOM: Remove the named attribute.

getAttributeNode

public Attr getAttributeNode(java.lang.String name)
DOM: returns the attribute

setAttributeNode

public Attr setAttributeNode(Attr newAttr)
                      throws DOMException
DOM: assigns the attribute

removeAttributeNode

public Attr removeAttributeNode(Attr oldAttr)
                         throws DOMException
DOM: removes the attribute with the same name as this one

normalize

public void normalize()
DOM: Merges all adjacent Text nodes in the tree rooted by this element. Avoid using this on large blocks of text not separated by markup such as elements or processing instructions, since it can require arbitrarily large blocks of contiguous memory.

As a compatible extension to DOM, this normalizes treatment of whitespace except when the xml:space='preserve' attribute value applies to a node. All whitespace is normalized to one space. This ensures that text which is pretty-printed and then reread (and normalized) retains the same content.


cloneNode

public Node cloneNode(boolean deep)
Creates a new unparented node whose attributes are the same as this node's attributes; if deep is true, the children of this node are cloned as children of the new node.

write

public void write(java.io.Writer out)
           throws java.io.IOException
Convenience method to construct a non-prettyprinting XML write context and call writeXml with it. Subclasses may choose to to override this method to generate non-XML text,
Parameters:
out - where to emit the XML content of this node


Submit Feedback to xml-feedback@java.sun.com
Copyright © 1998-1999 Sun Microsystems, Inc. All Rights Reserved.

Sun Microsystems, Inc.
901 San Antonio Road
Palo Alto, California, 94303, U.S.A.