public class ElementImpl implements Element { // Fields protected Attributes attrlist; // Constructors public ElementImpl(); public ElementImpl(Name tag, int type); // 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 attrName); 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 boolean isAttributeQualified(Name attr, DTD dtd); public int numAttributes(); public int numElements(); public Name qualifyName(String string); public void removeAttribute(String name); public void removeAttribute(Name attrName); public void removeChild(Element elem); public void save(XMLOutputStream o) throws IOException; public void saveAttributes(Atom ns, XMLOutputStream o) throws IOException; public void setAttribute(String name, Object value); public void setAttribute(Name attrName, Object value); public void setParent(Element parent); public void setText(String text); public Element toSchema(); public String toString(); }
This class represents the default implementation of the Element interface. These are created by the XML parser when using the default element factory.
Also see Element, Parser, ElementFactory, ElementFactoryImpl
public ElementImpl();
public ElementImpl(Name tag, int type);
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; returns null if the attribute is not found.
Parameter Description name The name of the attribute.
public Object getAttribute(Name attrName);Retrieves an attribute's value given its name.
Return Value
Returns the value of the attribute; returns 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. This method 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. This method must not return null. See EnumWrapper for an empty enumeration.
Return Value
Returns element collection 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 object itself, has a parent.
Return Value
Returns the parent element or null if the element is 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 method 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 the element type.
public boolean isAttributeQualified(Name attr, DTD dtd);Determines if the attribute is qualified.
Return Value
Returns true if the attribute is qualified; otherwise, returns false.
Parameter Description attr The name of the attribute. dtd The Document Definition Type (DTD) in which the attribute is found.
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 Name qualifyName(String string);This is a useful method for creating a qualified Name object from the given string. This will parse the string and lookup the namespace, if specified, and create the fully qualified name. If no namespace is given, it will inherit the namespace from this element.
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 attrName);Deletes an attribute from an element.
Parameter Description attrName The attribute name to delete.
public void removeChild(Element elem);Removes a child element from the tree.
Return Value
No return value.
Parameter Description elem The element to remove.
public void save(XMLOutputStream o) throws IOException;Saves the element in XML format.
Return Value
No return value.
Parameter Description o The output stream to save to. Exceptions
>IOException if an error occurs when writing to the output stream.
public void saveAttributes(Atom ns, XMLOutputStream o) throws IOException;Save the element attributes in XML format
public void setAttribute(String name, Object value);Sets the attribute of this element.
Return Value
Returns any previous value, if any.
Parameter Description name The attribute name. value The attribute value.
public void setAttribute(Name attrName, Object value);Sets the attribute of this element.
Parameter Description attrName 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 the parent.
public void setText(String text);Sets the text for this element. This text is Only meaningful in CDATA, PCDATA, and COMMENT nodes.
Parameter Description 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.
public String toString();Retrieves the string representation of this element.
Return Value
Returns a string representing the element.