FileDocCategorySizeDatePackage
Element.javaAPI DocAndroid 1.5 API6444Wed May 06 22:42:00 BST 2009android.sax

Element

public class Element extends Object
An XML element. Provides access to child elements and hooks to listen for events related to this element.
see
RootElement

Fields Summary
final String
uri
final String
localName
final int
depth
final Element
parent
Children
children
ArrayList
requiredChilden
boolean
visited
StartElementListener
startElementListener
EndElementListener
endElementListener
EndTextElementListener
endTextElementListener
Constructors Summary
Element(Element parent, String uri, String localName, int depth)

        this.parent = parent;
        this.uri = uri;
        this.localName = localName;
        this.depth = depth;
    
Methods Summary
voidcheckRequiredChildren(org.xml.sax.Locator locator)
Throws an exception if a required child was not present.

        ArrayList<Element> requiredChildren = this.requiredChilden;
        if (requiredChildren != null) {
            for (int i = requiredChildren.size() - 1; i >= 0; i--) {
                Element child = requiredChildren.get(i);
                if (!child.visited) {
                    throw new BadXmlException(
                            "Element named " + this + " is missing required"
                                    + " child element named "
                                    + child + ".", locator);
                }
            }
        }
    
public android.sax.ElementgetChild(java.lang.String localName)
Gets the child element with the given name. Uses an empty string as the namespace.

        return getChild("", localName);
    
public android.sax.ElementgetChild(java.lang.String uri, java.lang.String localName)
Gets the child element with the given name.

        if (endTextElementListener != null) {
            throw new IllegalStateException("This element already has an end"
                    + " text element listener. It cannot have children.");
        }

        if (children == null) {
            children = new Children();
        }

        return children.getOrCreate(this, uri, localName);
    
public android.sax.ElementrequireChild(java.lang.String localName)
Gets the child element with the given name. Uses an empty string as the namespace. We will throw a {@link org.xml.sax.SAXException} at parsing time if the specified child is missing. This helps you ensure that your listeners are called.

        return requireChild("", localName);
    
public android.sax.ElementrequireChild(java.lang.String uri, java.lang.String localName)
Gets the child element with the given name. We will throw a {@link org.xml.sax.SAXException} at parsing time if the specified child is missing. This helps you ensure that your listeners are called.

        Element child = getChild(uri, localName);

        if (requiredChilden == null) {
            requiredChilden = new ArrayList<Element>();
            requiredChilden.add(child);
        } else {
            if (!requiredChilden.contains(child)) {
                requiredChilden.add(child);
            }
        }

        return child;
    
voidresetRequiredChildren()
Clears flags on required children.

        ArrayList<Element> requiredChildren = this.requiredChilden;
        if (requiredChildren != null) {
            for (int i = requiredChildren.size() - 1; i >= 0; i--) {
                requiredChildren.get(i).visited = false;
            }
        }
    
public voidsetElementListener(ElementListener elementListener)
Sets start and end element listeners at the same time.

        setStartElementListener(elementListener);
        setEndElementListener(elementListener);
    
public voidsetEndElementListener(EndElementListener endElementListener)
Sets a listener for the end of this element.

        if (this.endElementListener != null) {
            throw new IllegalStateException(
                    "End element listener has already been set.");
        }
        this.endElementListener = endElementListener;
    
public voidsetEndTextElementListener(EndTextElementListener endTextElementListener)
Sets a listener for the end of this text element.

        if (this.endTextElementListener != null) {
            throw new IllegalStateException(
                    "End text element listener has already been set.");
        }

        if (children != null) {
            throw new IllegalStateException("This element already has children."
                    + " It cannot have an end text element listener.");
        }

        this.endTextElementListener = endTextElementListener;
    
public voidsetStartElementListener(StartElementListener startElementListener)
Sets a listener for the start of this element.

        if (this.startElementListener != null) {
            throw new IllegalStateException(
                    "Start element listener has already been set.");
        }
        this.startElementListener = startElementListener;
    
public voidsetTextElementListener(TextElementListener elementListener)
Sets start and end text element listeners at the same time.

        setStartElementListener(elementListener);
        setEndTextElementListener(elementListener);
    
public java.lang.StringtoString()

        return toString(uri, localName);
    
static java.lang.StringtoString(java.lang.String uri, java.lang.String localName)

        return "'" + (uri.equals("") ? localName : uri + ":" + localName) + "'";