Class ElementImpl

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

Constructors

ElementImpl

public ElementImpl();

ElementImpl

public ElementImpl(Name tag, int type);

Methods

addChild 

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.

ParameterDescription
elemThe 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.
afterThe element after which to add it.

addChild 

public void addChild(Element elem, int pos, int reserved);

Adds a child to this element.

Return Value

No return value.

ParameterDescription
elemThe element to add.
posThe position to add this element (calling getChild(pos) will return this element). If pos is less than 0, elem becomes the new last element.
reservedThe reserved parameter.

getAttribute 

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.

ParameterDescription
nameThe name of the attribute.

getAttribute 

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.

ParameterDescription
nameThe name of the attribute.

getAttributes 

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

getChild 

public Element getChild(int index);

Retrieves the child element by index.

Return Value

Returns null if there is no child by that index.

ParameterDescription
indexThe index of the child element.

getChildren 

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.

getElements 

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.

getParent 

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.

getTagName 

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.

getText 

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:

<AUTHOR> <FIRST>William</FIRST> <LAST>Shakespeare</LAST> </AUTHOR>

Document.getText returns "William Shakespeare".

getType 

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.

isAttributeQualified 

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.

ParameterDescription
attrThe name of the attribute.
dtdThe Document Definition Type (DTD) in which the attribute is found.

numAttributes 

public int numAttributes();

Retrieves the number of attributes.

Return Value

Returns the number of attributes.

numElements 

public int numElements();

Retrieves the number of child elements.

Return Value

Returns the number of child elements.

qualifyName 

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.

removeAttribute 

public void removeAttribute(String name);

Deletes an attribute from an element.

Return Value

No return value.

ParameterDescription
nameThe attribute to delete.

removeAttribute 

public void removeAttribute(Name attrName);

Deletes an attribute from an element.

ParameterDescription
attrNameThe attribute name to delete.

removeChild 

public void removeChild(Element elem);

Removes a child element from the tree.

Return Value

No return value.

ParameterDescription
elemThe element to remove.

save 

public void save(XMLOutputStream o) throws IOException;

Saves the element in XML format.

Return Value

No return value.

ParameterDescription
oThe output stream to save to.

Exceptions

>IOException if an error occurs when writing to the output stream.

saveAttributes 

public void saveAttributes(Atom ns, XMLOutputStream o)
        throws IOException;

Save the element attributes in XML format

setAttribute 

public void setAttribute(String name, Object value);

Sets the attribute of this element.

Return Value

Returns any previous value, if any.

ParameterDescription
nameThe attribute name.
valueThe attribute value.

setAttribute 

public void setAttribute(Name attrName, Object value);

Sets the attribute of this element.

ParameterDescription
attrNameThe attribute name.
valueThe attribute value.

setParent 

public void setParent(Element parent);

Sets the parent of this element.

Return Value

No return value.

ParameterDescription
parentThe element to set as the parent.

setText 

public void setText(String text);

Sets the text for this element. This text is Only meaningful in CDATA, PCDATA, and COMMENT nodes.

ParameterDescription
Thetext to set.

toSchema 

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.

toString 

public String toString();

Retrieves the string representation of this element.

Return Value

Returns a string representing the element.

Fields 

attrlist
The attribute list.