Methods Summary |
---|
public void | close()Close this SimplePullParser and any underlying resources (e.g., its InputStream or
Reader source) used by this SimplePullParser.
if (source != null) {
try {
source.close();
} catch (IOException ioe) {
// ignore
}
}
|
public java.lang.String | getAttributeName(int i)Returns the name of the nth attribute on the current element.
return mParser.getAttributeName(i);
|
public java.lang.String | getAttributeNamespace(int i)Returns the namespace of the nth attribute on the current element.
return mParser.getAttributeNamespace(i);
|
public int | getDepth()Returns the depth of the current element. The depth is 0 before the first
element has been returned, 1 after that, etc.
return mParser.getDepth();
|
public int | getIntAttribute(java.lang.String namespace, java.lang.String name, int defaultValue)Returns the string value of the named attribute. An exception will
be thrown if the attribute is not a valid integer.
String value = mParser.getAttributeValue(namespace, name);
if (null == value) return defaultValue;
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
throw new ParseException("Cannot parse '" + value + "' as an integer");
}
|
public int | getIntAttribute(java.lang.String namespace, java.lang.String name)Returns the string value of the named attribute. An exception will
be thrown if the attribute is not present or is not a valid integer.
String value = getStringAttribute(namespace, name);
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
throw new ParseException("Cannot parse '" + value + "' as an integer");
}
|
public long | getLongAttribute(java.lang.String namespace, java.lang.String name, long defaultValue)Returns the string value of the named attribute. An exception will
be thrown if the attribute is not a valid long.
String value = mParser.getAttributeValue(namespace, name);
if (null == value) return defaultValue;
try {
return Long.parseLong(value);
} catch (NumberFormatException e) {
throw new ParseException("Cannot parse '" + value + "' as a long");
}
|
public long | getLongAttribute(java.lang.String namespace, java.lang.String name)Returns the string value of the named attribute. An exception will
be thrown if the attribute is not present or is not a valid long.
String value = getStringAttribute(namespace, name);
try {
return Long.parseLong(value);
} catch (NumberFormatException e) {
throw new ParseException("Cannot parse '" + value + "' as a long");
}
|
public java.lang.String | getStringAttribute(java.lang.String namespace, java.lang.String name, java.lang.String defaultValue)Returns the string value of the named attribute.
String value = mParser.getAttributeValue(namespace, name);
if (null == value) return defaultValue;
return value;
|
public java.lang.String | getStringAttribute(java.lang.String namespace, java.lang.String name)Returns the string value of the named attribute. An exception will
be thrown if the attribute is not present.
String value = mParser.getAttributeValue(namespace, name);
if (null == value) {
throw new ParseException(
"missing '" + name + "' attribute on '" + mCurrentStartTag + "' element");
}
return value;
|
private static void | moveToStartDocument(org.xmlpull.v1.XmlPullParser parser)
int eventType;
eventType = parser.getEventType();
if (eventType != XmlPullParser.START_DOCUMENT) {
throw new XmlPullParserException("Not at start of response");
}
|
public java.lang.String | nextTag(int parentDepth)The same as nextTagOrTexxt(int, StringBuilder) but ignores text blocks.
return nextTagOrText(parentDepth, null /* ignore text */);
|
public java.lang.String | nextTagOrText(int parentDepth, java.lang.StringBuilder textBuilder)Returns the tag of the next element whose depth is parentDepth plus one
or null if there are no more such elements before the next start tag. When this returns,
getDepth() and all methods relating to attributes will refer to the element whose tag is
returned.
while (true) {
int eventType = 0;
try {
eventType = mParser.next();
} catch (XmlPullParserException e) {
throw new ParseException(e);
}
int depth = mParser.getDepth();
mCurrentStartTag = null;
if (eventType == XmlPullParser.START_TAG && depth == parentDepth + 1) {
mCurrentStartTag = mParser.getName();
if (mLogTag != null && Log.isLoggable(mLogTag, Log.DEBUG)) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < depth; i++) sb.append(" ");
sb.append("<").append(mParser.getName());
int count = mParser.getAttributeCount();
for (int i = 0; i < count; i++) {
sb.append(" ");
sb.append(mParser.getAttributeName(i));
sb.append("=\"");
sb.append(mParser.getAttributeValue(i));
sb.append("\"");
}
sb.append(">");
Log.d(mLogTag, sb.toString());
}
return mParser.getName();
}
if (eventType == XmlPullParser.END_TAG && depth == parentDepth) {
if (mLogTag != null && Log.isLoggable(mLogTag, Log.DEBUG)) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < depth; i++) sb.append(" ");
sb.append("</>"); // Not quite valid xml but it gets the job done.
Log.d(mLogTag, sb.toString());
}
return null;
}
if (eventType == XmlPullParser.END_DOCUMENT && parentDepth == 0) {
// we could just rely on the caller calling close(), which it should, but try
// to auto-close for clients that might have missed doing so.
if (source != null) {
source.close();
source = null;
}
return null;
}
if (eventType == XmlPullParser.TEXT && depth == parentDepth) {
if (textBuilder == null) {
continue;
}
String text = mParser.getText();
textBuilder.append(text);
return TEXT_TAG;
}
}
|
public int | numAttributes()Returns the number of attributes on the current element.
return mParser.getAttributeCount();
|
public void | readRemainingText(int parentDepth, java.lang.StringBuilder textBuilder)Consumes the rest of the children, accumulating any text at this level into the builder.
while (nextTagOrText(parentDepth, textBuilder) != null) {
}
|
public void | setLogTag(java.lang.String logTag)Enables logging to the provided log tag. A basic representation of the xml will be logged as
the xml is parsed. No logging is done unless this is called.
mLogTag = logTag;
|