Methods Summary |
---|
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)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;
|
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 | nextTag(int parentDepth)The same as nextTagOrText(int, StringBuilder) but ignores text blocks.
return nextTagOrText(parentDepth, null /* ignore text */);
|
public java.lang.String | nextTagOrText(int parentDepth, java.lang.StringBuffer textBuffer)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();
// TODO: this is an example of how to do logging of the XML
// 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) {
// TODO: this is an example of how to do logging of the XML
// 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) {
return null;
}
if (eventType == XmlPullParser.TEXT && depth == parentDepth) {
if (textBuffer == null) {
continue;
}
String text = mParser.getText();
textBuffer.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.StringBuffer textBuffer)Consumes the rest of the children, accumulating any text at this level into the builder.
while (nextTagOrText(parentDepth, textBuffer) != null) {
}
|