public interface Element { // Fields static public final int CDATA; static public final int COMMENT; static public final int DOCUMENT; static public final int DTD; static public final int ELEMENT; static public final int ELEMENTDECL; static public final int ENTITY; static public final int ENTITYREF; static public final int IGNORESECTION; static public final int INCLUDESECTION; static public final int NAMESPACE; static public final int NOTATION; static public final int PCDATA; static public final int PI; static public final int WHITESPACE; // Methods public void addChild(Element elem, Element after); public void addChild(Element elem, int pos, int reserved); public Object getAttribute(String name); public Object getAttribute(Name n); public Enumeration getAttributes(); public Element getChild(int index); public ElementCollection getChildren(); public Enumeration getElements(); public Element getParent(); public Name getTagName(); public String getText(); public int getType(); public int numAttributes(); public int numElements(); public void removeAttribute(String name); public void removeAttribute(Name name); public void removeChild(Element elem); public void save(XMLOutputStream o) throws IOException; public void setAttribute(String name, Object value); public void setAttribute(Name name, Object value); public void setParent(Element parent); public void setText(String text); public Element toSchema(); }
This interface implements an Element object. Each XML tag in a document is represented by an Element object in the XML parse tree. The elements are named with a string, have attributes, and can contain child nodes.
There are seven types of elements, DOCUMENT, ELEMENT, PCDATA, PI, META, COMMENT, and CDATA.
public void addChild(Element elem, Element after);Adds a child to this element. Any element can only have one parent element and so the previous parent will lose this child from its subtree.
Return Value
No return value.
Parameter Description elem The element to add. The child element becomes the last element if after is null. The child is added to the beginning of the list if after is this object. after The element after which to add it.
public void addChild(Element elem, int pos, int reserved);Adds a child to this element.
Return Value
No return value.
Parameter Description elem The element to add. pos The position to add this element (calling getChild(pos) will return this element). If pos is less than 0, elem becomes the new last element. reserved The reserved parameter.
public Object getAttribute(String name);Retrieves an attribute's value given its name.
Return Value
Returns the value of the attribute or null if the attribute is not found.
Parameter Description name The name of the attribute.
public Object getAttribute(Name n);Retrieves an attribute's value given its name.
Return Value
Returns the value of the attribute or null if the attribute is not found.
Parameter Description name The name of the attribute.
public Enumeration getAttributes();Retrieves an enumeration for the element attributes. The enumeration returns Attribute objects.
Return Value
Returns the enumeration. It must not return null (see EnumWrapper for returning empty enumerations).
See Also Attribute
public Element getChild(int index);Retrieves the child element by index.
Return Value
Returns null if there is no child by that index.
Parameter Description index The index of the child element.
public ElementCollection getChildren();Returns an element collection of the children of this element. It must not return null. See EnumWrapper for an emptyEnumeration.
Return Value
Returns ElementCollection of child objects.
public Enumeration getElements();Returns an enumeration of the children of this element. >Enumeration.nextElement returns Element objects.
Return Value
Returns an enumeration of child objects. It must not return null. See EnumWrapper for an easy way to return an empty enumeration.
public Element getParent();Retrieves the parent of this element. Every element in the tree except the Document itself, has a parent.
Return Value
Returns the parent element or null if at the root of the tree.
public Name getTagName();Retrieves the name of the tag as a string. The string will be in uppercase.
Return Value
Returns the tag name or null for DATA and PCDATA elements.
public String getText();Returns the non-marked-up text contained by this element. For text elements, this is the raw data. For elements with child nodes, this traverses the entire subtree and appends the text for each terminal text element, effectively stripping out the XML markup for the subtree. For example, if the XML document contains the following:
William Shakespeare Document.getText returns "William Shakespeare".
public int getType();Retrieves the type of the element. This is always one of the following values: DOCUMENT, ELEMENT, PCDATA, PI, META, COMMENT, or CDATA.
Return Value
Returns element type.
public int numAttributes();Retrieves the number of attributes.
Return Value
Returns the number of attributes.
public int numElements();Retrieves the number of child elements.
Return Value
Returns the number of child elements.
public void removeAttribute(String name);Deletes an attribute from an element.
Return Value
No return value.
Parameter Description name The attribute to delete.
public void removeAttribute(Name name);Deletes an attribute from an element.
Return Value
No return value.
Parameter Description name The attribute to delete.
public void removeChild(Element elem);Removes a child element from the tree.
Parameter Description elem The element to remove.
public void save(XMLOutputStream o) throws IOException;Saves this element.
Return Value
No return value.
Parameter Description o The output stream to save to. Exceptions
>IOException if there is a problem saving the output.
public void setAttribute(String name, Object value);Sets the attribute of this element.
Parameter Description name The attribute name. value The attribute value.
public void setAttribute(Name name, Object value);Sets the attribute of this element.
Parameter Description name The attribute name. value The attribute value.
public void setParent(Element parent);Sets the parent of this element.
Return Value
No return value.
Parameter Description parent The element to set as parent.
public void setText(String text);Sets the text for this element. Only meaningful in CDATA, PCDATA, and COMMENT nodes.
Return Value
No return value.
Parameter Description text The text to set.
public Element toSchema();Returns the XML-DATA specification for the DTD element. (Only applies to ElementDecl and Entity nodes). This is DTD information represented in an XML Object Model. See Specification for XML-Data for details.