com.hp.hpl.sparta
Class Element

java.lang.Object
  |
  +--com.hp.hpl.sparta.Node
        |
        +--com.hp.hpl.sparta.Element
All Implemented Interfaces:
java.lang.Cloneable

public class Element
extends Node

An XML Element.

Copyright (C) 2002 Hewlett-Packard Company. This file is part of Sparta, an XML Parser, DOM, and XPath library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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.

Version:
$Date: 2002/08/19 05:03:55 $ $Revision: 1.1.1.1 $
Author:
Eamonn O'Brien-Strain
See Also:
GNU Lesser General Public License, Element

Constructor Summary
Element(java.lang.String tagName)
           
 
Method Summary
 void appendChild(Node addedChild)
           
 java.lang.Object clone()
          Create a deep clone of this Element.
 Element cloneElement(boolean deep)
          Create a clone of this node.
 Element cloneShallow()
          Create a shallow clone of this Element.
 boolean equals(java.lang.Object thatO)
          To be equal elements must have the same tagname, they must have the same children (applying equals recursivly) in the same order and they must have the same attributes in any order.
 java.lang.String getAttribute(java.lang.String name)
           
 java.util.Enumeration getAttributeNames()
          Return enumeration of Strings
 Node getFirstChild()
           
 Node getLastChild()
           
 java.lang.String getTagName()
           
 void removeAttribute(java.lang.String name)
           
 void removeChild(Node childToRemove)
           
 void replaceChild(Element newChild, Node oldChild)
          Replace oldChild with newChild.
 void replaceChild(Text newChild, Node oldChild)
          Replace oldChild with newChild.
 void setAttribute(java.lang.String name, java.lang.String value)
           
 void setTagName(java.lang.String tagName)
           
 void toXml(java.io.Writer writer)
          Write XML representation to character stream.
 Element xpathSelectElement(java.lang.String xpath)
          Select the first element that matches the relative XPath expression with respect to this element, or null if there is no match.
 java.util.Enumeration xpathSelectElements(java.lang.String xpath)
          Select all the elements that match the relative XPath expression with respect to this element.
 java.lang.String xpathSelectString(java.lang.String xpath)
          Select the first element that matches the relative XPath expression with respect to this element, or null if there is no match.
 java.util.Enumeration xpathSelectStrings(java.lang.String xpath)
          Select all the strings that match the relative XPath expression with respect to this element.
 
Methods inherited from class com.hp.hpl.sparta.Node
getAnnotation, getNextSibling, getOwnerDocument, getParentNode, getPreviousSibling, htmlEncode, setAnnotation, toString, toXml, xpathEnsure, xpathSetStrings
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Element

public Element(java.lang.String tagName)
Method Detail

clone

public java.lang.Object clone()
Create a deep clone of this Element. It will have the tagname and attributes as this node. This method will be called recursively to copy the while subtree of child Elements and Text nodes.
Overrides:
clone in class Node

cloneShallow

public Element cloneShallow()
Create a shallow clone of this Element. It will have the tagname and attributes as this Element but will not have child Elements or Nodes.

cloneElement

public Element cloneElement(boolean deep)
Create a clone of this node. It will have the tagname and attributes as this node. If deep is true, this method will be called recursively to copy the while subtree of child Elements and text nodes.

getTagName

public java.lang.String getTagName()

setTagName

public void setTagName(java.lang.String tagName)

getFirstChild

public Node getFirstChild()

getLastChild

public Node getLastChild()

getAttributeNames

public java.util.Enumeration getAttributeNames()
Return enumeration of Strings

getAttribute

public java.lang.String getAttribute(java.lang.String name)

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String value)
Parameters:
name - attribute name which must be non-null, non empty
value - attribue value.

removeAttribute

public void removeAttribute(java.lang.String name)

appendChild

public void appendChild(Node addedChild)
                 throws DOMException

removeChild

public void removeChild(Node childToRemove)
                 throws DOMException

replaceChild

public void replaceChild(Element newChild,
                         Node oldChild)
                  throws DOMException
Replace oldChild with newChild.
Throws:
DOMException - if oldChild object is not a child.

replaceChild

public void replaceChild(Text newChild,
                         Node oldChild)
                  throws DOMException
Replace oldChild with newChild.
Throws:
DOMException - if oldChild object is not a child.

toXml

public void toXml(java.io.Writer writer)
           throws java.io.IOException
Write XML representation to character stream.

xpathSelectElements

public java.util.Enumeration xpathSelectElements(java.lang.String xpath)
                                          throws ParseException
Select all the elements that match the relative XPath expression with respect to this element.
Overrides:
xpathSelectElements in class Node

xpathSelectStrings

public java.util.Enumeration xpathSelectStrings(java.lang.String xpath)
                                         throws ParseException
Select all the strings that match the relative XPath expression with respect to this element.
Overrides:
xpathSelectStrings in class Node

xpathSelectElement

public Element xpathSelectElement(java.lang.String xpath)
                           throws ParseException
Select the first element that matches the relative XPath expression with respect to this element, or null if there is no match.
Overrides:
xpathSelectElement in class Node

xpathSelectString

public java.lang.String xpathSelectString(java.lang.String xpath)
                                   throws ParseException
Select the first element that matches the relative XPath expression with respect to this element, or null if there is no match.
Overrides:
xpathSelectString in class Node

equals

public boolean equals(java.lang.Object thatO)
To be equal elements must have the same tagname, they must have the same children (applying equals recursivly) in the same order and they must have the same attributes in any order. Elements can be equal even if they are in different documents, have different parents, have different siblings, or have different annotations.
Overrides:
equals in class java.lang.Object