Packages
 In this topic

*Constructors

*Methods

*Fields

 

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

 


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 void removeAttribute(String name);
  public void removeAttribute(Name attrName);
  public void removeChild(Element elem);
  public void save(XMLOutputStream o) throws IOException;
  public void saveAttributes(Name ns, XMLOutputStream o)
        throws IOException;
  public void saveText(String str, 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 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 com.ms.xml.om.Element, Parser, com.ms.xml.om.ElementFactory, com.ms.xml.om.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
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; returns null if the attribute is not found.

ParameterDescription
name The 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
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. 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
index The 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: <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 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
attr The name of the attribute.
dtd The 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.

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 attrName);

Deletes an attribute from an element.

ParameterDescription
attrName The attribute name to delete.

removeChild

public void removeChild(Element elem);

Removes a child element from the tree.

Return Value:

No return value.

ParameterDescription
elem The element to remove.

save

public void save(XMLOutputStream o) throws IOException;

Saves the element in XML format.

Return Value:

No return value.

ParameterDescription
o The output stream to save to.

Exceptions:

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

saveAttributes

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

Saves the element attributes in XML format.

Return Value:

No return value.

ParameterDescription
ns The name of the element attribute.
o The output stream to save to.

Exceptions:

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

saveText

public void saveText(String str, XMLOutputStream o) throws IOException;

Saves the text out restoring any built-in entities that may be needed to keep the document valid.

Return Value:

No return value.

ParameterDescription
str The text to save.
o The output stream to save to.

Exceptions:

IOException if an error occurs when writing to the output stream

setAttribute

public void setAttribute(String name, Object value);

Sets the attribute of this element.

Return Value:

Returns any previous value, if any.

ParameterDescription
name The attribute name.
value The attribute value.

setAttribute

public void setAttribute(Name attrName, Object value);

Sets the attribute of this element.

ParameterDescription
attrName 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 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
The text to set.

toString

public String toString();

Retrieves the string representation of this element.

Return Value:

Returns a string representing the element.

Fields

attrlist
The attribute list.

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