FileDocCategorySizeDatePackage
XmlUtils.javaAPI DocAndroid 1.5 API5445Wed May 06 22:41:16 BST 2009com.google.wireless.gdata.data

XmlUtils

public final class XmlUtils extends Object
Utility class for working with an XmlPullParser.

Fields Summary
Constructors Summary
private XmlUtils()

    
Methods Summary
public static java.lang.StringextractChildText(org.xmlpull.v1.XmlPullParser parser)
Extracts the child text for the current element in the pull parser.

param
parser The XmlPullParser parsing an XML document.
return
The child text for the current element. May be null, if there is no child text.
throws
XmlPullParserException Thrown if the child text could not be parsed.
throws
IOException Thrown if the InputStream behind the parser cannot be read.

        // TODO: check that the current node is an element?
        int eventType = parser.next();
        if (eventType != XmlPullParser.TEXT) {
            return null;
        }
        return parser.getText();
    
public static java.lang.StringextractFirstChildTextIgnoreRest(org.xmlpull.v1.XmlPullParser parser)

        int parentDepth = parser.getDepth();
        int eventType = parser.next();
        String child = null;
        while (eventType != XmlPullParser.END_DOCUMENT) {
            int depth = parser.getDepth();

            if (eventType == XmlPullParser.TEXT) {
                if (child == null) {
                    child = parser.getText();
                }
            } else if (eventType == XmlPullParser.END_TAG && depth == parentDepth) {
                return child;
            }
            eventType = parser.next();
        }
        throw new XmlPullParserException("End of document reached; never saw expected end tag at "
                + "depth " + parentDepth);
    
public static java.lang.StringnextDirectChildTag(org.xmlpull.v1.XmlPullParser parser, int parentDepth)

        int targetDepth = parentDepth + 1;
        int eventType = parser.next();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            int depth = parser.getDepth();

            if (eventType == XmlPullParser.START_TAG && depth == targetDepth) {
                return parser.getName();
            }

            if (eventType == XmlPullParser.END_TAG && depth == parentDepth) {
                return null;
            }
            eventType = parser.next();            
        }
        throw new XmlPullParserException("End of document reached; never saw expected end tag at "
                + "depth " + parentDepth);