Packages
 In this topic

*Methods

*Fields

 

Packages   PreviousThis PackageNext
Package com.ms.xml.om   Previous This
Package
Next

 


Interface Element

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 NAMESPACE;
  static public final int NOTATION;
  static public final int PCDATA;
  static public final int PI;

  // 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);
}

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.

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
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.

addChild

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

Adds a child to this element.

Return Value:

No return value.

ParameterDescription
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.

getAttribute

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.

ParameterDescription
name The name of the attribute.

getAttribute

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.

ParameterDescription
name The 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. It 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
index The index of the child element.

getChildren

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.

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 itself, has a parent.

Return Value:

Returns the parent element or null if 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 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: <xmp> <AUTHOR> <FIRST>William</FIRST> <LAST>Shakespeare</LAST> </AUTHOR> </xmp>

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 element type.

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.

removeAttribute

public void removeAttribute(String name);

Deletes an attribute from an element.

Return Value:

No return value.

ParameterDescription
name The attribute to delete.

removeAttribute

public void removeAttribute(Name name);

Deletes an attribute from an element.

Return Value:

No return value.

ParameterDescription
name The attribute to delete.

removeChild

public void removeChild(Element elem);

Removes a child element from the tree.

ParameterDescription
elem The element to remove.

save

public void save(XMLOutputStream o) throws IOException;

Saves this element.

Return Value:

No return value.

ParameterDescription
o The output stream to save to.

Exceptions:

IOException if there is a problem saving the output.

setAttribute

public void setAttribute(String name, Object value);

Sets the attribute of this element.

ParameterDescription
name The attribute name.
value The attribute value.

setAttribute

public void setAttribute(Name name, Object value);

Sets the attribute of this element.

ParameterDescription
name The attribute name.
value The attribute value.

setParent

public void setParent(Element parent);

Sets the parent of this element.

Return Value:

No return value.

ParameterDescription
parent The element to set as parent.

setText

public void setText(String text);

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

Return Value:

No return value.

ParameterDescription
text The text to set.

Fields

CDATA
Raw character data specified with special CDATA construct: <![CDATA[...]]> where ... can be anything except ]]>, including HTML tags.
COMMENT
An XML comment ( <!-- ... --> ).
DOCUMENT
Reserved for use by the Document node only.
DTD
Reserved for use by the DTD node only.
ELEMENT
A general container element having optional attributes and optional child elements.
ELEMENTDECL
An element declaration node.
ENTITY
An entity node.
ENTITYREF
Entity reference nodes.
NAMESPACE
A namespace node that declares new namespaces in the element tree.
NOTATION
A notation node.
PCDATA
A text element that has no children or attributes and that contains parsed character data.
PI
A processing instruction node ( <? ... ?> ).

upnrm.gif © 1998 Microsoft Corporation. All rights reserved. Terms of use.