Code example for XmlPullParser

Methods: getDepth, getLineNumber, isWhitespace, next

0
    public String getText() {
        return mParser.getText();
    } 
 
    public int getLineNumber() { 
        return mParser.getLineNumber();
    } 
 
    public int getEventType() { 
        return mEventType;
    } 
 
    public boolean isWhitespace() throws XmlPullParserException { 
        // Original comment: whitespace was stripped by aapt. 
        return mParser.isWhitespace();
    } 
 
    public String getPrefix() {
        throw new RuntimeException("getPrefix not supported");
    } 
 
    public char[] getTextCharacters(int[] holderForStartAndLength) {
        String txt = getText();
        char[] chars = null;
        if (txt != null) {
            holderForStartAndLength[0] = 0;
            holderForStartAndLength[1] = txt.length();
            chars = new char[txt.length()];
            txt.getChars(0, txt.length(), chars, 0);
        } 
        return chars;
    } 
 
    public String getNamespace() {
        return mParser.getNamespace();
    } 
 
    public String getName() {
        return mParser.getName();
    } 
 
    public String getAttributeNamespace(int index) {
        return mParser.getAttributeNamespace(index);
    } 
 
    public String getAttributeName(int index) {
        return mParser.getAttributeName(index);
    } 
 
    public String getAttributePrefix(int index) {
        throw new RuntimeException("getAttributePrefix not supported");
    } 
 
    public boolean isEmptyElementTag() { 
        // XXX Need to detect this. 
        return false; 
    } 
 
    public int getAttributeCount() { 
        return mParser.getAttributeCount();
    } 
 
    public String getAttributeValue(int index) {
        return mParser.getAttributeValue(index);
    } 
 
    public String getAttributeType(int index) {
        return "CDATA"; 
    } 
 
    public boolean isAttributeDefault(int index) {
        return false; 
    } 
 
    public int nextToken() throws XmlPullParserException, IOException { 
        return next(); 
    } 
 
    public String getAttributeValue(String namespace, String name) {
        return mParser.getAttributeValue(namespace, name);
    } 
 
    public int next() throws XmlPullParserException, IOException { 
        if (!mStarted) {
            mStarted = true;
            return START_DOCUMENT;
        } 
        int ev = mParser.next();
 
        if (ev == END_TAG && mParser.getDepth() == 1) {
            // done with parser remove it from the context stack. 
            ensurePopped(); 
        } 
        mEventType = ev;
        return ev;