/** * Returns the type of the current event (START_TAG, END_TAG, TEXT, etc.) * * @see #next() * @see #nextToken() */ intgetEventType()throws XmlPullParserException;
/** * This array can be used to convert the event type integer constants * such as START_TAG or TEXT to * to a string. For example, the value of TYPES[START_TAG] is * the string "START_TAG". * * This array is intended for diagnostic output only. Relying * on the contents of the array may be dangerous since malicious * applications may alter the array, although it is final, due * to limitations of the Java language. */ String [] TYPES = { "START_DOCUMENT", "END_DOCUMENT", "START_TAG", "END_TAG", "TEXT", "CDSECT", "ENTITY_REF", "IGNORABLE_WHITESPACE", "PROCESSING_INSTRUCTION", "COMMENT", "DOCDECL" };
int START_DOCUMENT = 0; int END_DOCUMENT = 1; int START_TAG = 2; int END_TAG = 3; int TEXT = 4; int CDSECT = 5; int ENTITY_REF = 6; int IGNORABLE_WHITESPACE = 7; int PROCESSING_INSTRUCTION = 8; int COMMENT = 9; int DOCDECL = 10;
1 2 3 4 5 6 7 8 9 10 11 12 13
/** * For START_TAG or END_TAG events, the (local) name of the current * element is returned when namespaces are enabled. When namespace * processing is disabled, the raw name is returned. * For ENTITY_REF events, the entity name is returned. * If the current event is not START_TAG, END_TAG, or ENTITY_REF, * null is returned. * <p><b>Please note:</b> To reconstruct the raw element name * when namespaces are enabled and the prefix is not null, * you will need to add the prefix and a colon to localName.. * */ String getName();
/** * Returns the given attributes value. * Throws an IndexOutOfBoundsException if the index is out of range * or current event type is not START_TAG. * * <p><strong>NOTE:</strong> attribute value must be normalized * (including entity replacement text if PROCESS_DOCDECL is false) as described in * <a href="http://www.w3.org/TR/REC-xml#AVNormalize">XML 1.0 section * 3.3.3 Attribute-Value Normalization</a> * * @see #defineEntityReplacementText * * @param index zero-based index of attribute * @return value of attribute (null is never returned) */ String getAttributeValue(int index);
/** * Returns the attributes value identified by namespace URI and namespace localName. * If namespaces are disabled namespace must be null. * If current event type is not START_TAG then IndexOutOfBoundsException will be thrown. * * <p><strong>NOTE:</strong> attribute value must be normalized * (including entity replacement text if PROCESS_DOCDECL is false) as described in * <a href="http://www.w3.org/TR/REC-xml#AVNormalize">XML 1.0 section * 3.3.3 Attribute-Value Normalization</a> * * @see #defineEntityReplacementText * * @param namespace Namespace of the attribute if namespaces are enabled otherwise must be null * @param name If namespaces enabled local name of attribute otherwise just attribute name * @return value of attribute or null if attribute with given name does not exist */ String getAttributeValue(String namespace, String name);
/** * If current event is START_TAG then if next element is TEXT then element content is returned * or if next event is END_TAG then empty string is returned, otherwise exception is thrown. * After calling this function successfully parser will be positioned on END_TAG. * * <p>The motivation for this function is to allow to parse consistently both * empty elements and elements that has non empty content, for example for input: <ol> * <li><tag>foo</tag> * <li><tag></tag> (which is equivalent to <tag/> * both input can be parsed with the same code: * <pre> * p.nextTag() * p.requireEvent(p.START_TAG, "", "tag"); * String content = p.nextText(); * p.requireEvent(p.END_TAG, "", "tag"); * </pre> * This function together with nextTag make it very easy to parse XML that has * no mixed content. * * * <p>Essentially it does this * <pre> * if(getEventType() != START_TAG) { * throw new XmlPullParserException( * "parser must be on START_TAG to read next text", this, null); * } * int eventType = next(); * if(eventType == TEXT) { * String result = getText(); * eventType = next(); * if(eventType != END_TAG) { * throw new XmlPullParserException( * "event TEXT it must be immediately followed by END_TAG", this, null); * } * return result; * } else if(eventType == END_TAG) { * return ""; * } else { * throw new XmlPullParserException( * "parser must be on START_TAG or TEXT to read text", this, null); * } * </pre> * * <p><strong>Warning:</strong> Prior to API level 14, the pull parser returned by {@code * android.util.Xml} did not always advance to the END_TAG event when this method was called. * Work around by using manually advancing after calls to nextText(): <pre> * String text = xpp.nextText(); * if (xpp.getEventType() != XmlPullParser.END_TAG) { * xpp.next(); * } * </pre> */ String nextText()throws XmlPullParserException, IOException;
/** * Get next parsing event - element content will be coalesced and only one * TEXT event must be returned for whole element content * (comments and processing instructions will be ignored and entity references * must be expanded or exception must be thrown if entity reference can not be expanded). * If element content is empty (content is "") then no TEXT event will be reported. * * <p><b>NOTE:</b> empty element (such as <tag/>) will be reported * with two separate events: START_TAG, END_TAG - it must be so to preserve * parsing equivalency of empty element to <tag></tag>. * (see isEmptyElementTag ()) * * @see #isEmptyElementTag * @see #START_TAG * @see #TEXT * @see #END_TAG * @see #END_DOCUMENT */