Package org.xmlpull.v1.util
Class XmlPullUtil
- java.lang.Object
-
- org.xmlpull.v1.util.XmlPullUtil
-
public class XmlPullUtil extends Object
Handy functions that combines XmlPull API into higher level functionality.- Author:
- Aleksander Slominski, Naresh Bhatia
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringgetAttributeValue(XmlPullParser pp, String name)Return value of attribute with given name and no namespace.static StringgetPIData(XmlPullParser pp)Return everything past PITarget and S from Processing Instruction (PI) as defined in XML 1.0 Section 2.6 Processing Instructions[16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'static StringgetPITarget(XmlPullParser pp)Return PITarget from Processing Instruction (PI) as defined in XML 1.0 Section 2.6 Processing Instructions[16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'static StringgetRequiredAttributeValue(XmlPullParser pp, String namespace, String name)Read attribute value and return it or throw exception if current element does not have such attribute.static booleanmatches(XmlPullParser pp, int type, String namespace, String name)Tests if the current event is of the given type and if the namespace and name match.static voidnextEndTag(XmlPullParser pp)Call parser nextTag() and check that it is END_TAG, throw exception if not.static voidnextEndTag(XmlPullParser pp, String namespace, String name)combine nextTag(); pp.require(XmlPullParser.END_TAG, namespace, name);static voidnextStartTag(XmlPullParser pp)call parser nextTag() and check that it is START_TAG, throw exception if not.static voidnextStartTag(XmlPullParser pp, String name)combine nextTag(); pp.require(XmlPullParser.START_TAG, null, name);static voidnextStartTag(XmlPullParser pp, String namespace, String name)combine nextTag(); pp.require(XmlPullParser.START_TAG, namespace, name);static StringnextText(XmlPullParser pp, String namespace, String name)Read text content of element ith given namespace and name (use null namespace do indicate that nemspace should not be checked)static voidskipSubTree(XmlPullParser pp)Skip sub tree that is currently porser positioned on.static voidwriteSimpleElement(XmlSerializer serializer, String namespace, String elementName, String elementText)Writes a simple element such asjohndoe .
-
-
-
Field Detail
-
XSI_NS
public static final String XSI_NS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getAttributeValue
public static String getAttributeValue(XmlPullParser pp, String name)
Return value of attribute with given name and no namespace.
-
getPITarget
public static String getPITarget(XmlPullParser pp) throws IllegalStateException
Return PITarget from Processing Instruction (PI) as defined in XML 1.0 Section 2.6 Processing Instructions[16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'- Throws:
IllegalStateException
-
getPIData
public static String getPIData(XmlPullParser pp) throws IllegalStateException
Return everything past PITarget and S from Processing Instruction (PI) as defined in XML 1.0 Section 2.6 Processing Instructions[16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'NOTE: if there is no PI data it returns empty string.
- Throws:
IllegalStateException
-
skipSubTree
public static void skipSubTree(XmlPullParser pp) throws XmlPullParserException, IOException
Skip sub tree that is currently porser positioned on.
NOTE: parser must be on START_TAG and when funtion returns parser will be positioned on corresponding END_TAG- Throws:
XmlPullParserExceptionIOException
-
nextStartTag
public static void nextStartTag(XmlPullParser pp) throws XmlPullParserException, IOException
call parser nextTag() and check that it is START_TAG, throw exception if not.- Throws:
XmlPullParserExceptionIOException
-
nextStartTag
public static void nextStartTag(XmlPullParser pp, String name) throws XmlPullParserException, IOException
combine nextTag(); pp.require(XmlPullParser.START_TAG, null, name);- Throws:
XmlPullParserExceptionIOException
-
nextStartTag
public static void nextStartTag(XmlPullParser pp, String namespace, String name) throws XmlPullParserException, IOException
combine nextTag(); pp.require(XmlPullParser.START_TAG, namespace, name);- Throws:
XmlPullParserExceptionIOException
-
nextEndTag
public static void nextEndTag(XmlPullParser pp, String namespace, String name) throws XmlPullParserException, IOException
combine nextTag(); pp.require(XmlPullParser.END_TAG, namespace, name);- Throws:
XmlPullParserExceptionIOException
-
nextText
public static String nextText(XmlPullParser pp, String namespace, String name) throws IOException, XmlPullParserException
Read text content of element ith given namespace and name (use null namespace do indicate that nemspace should not be checked)- Throws:
IOExceptionXmlPullParserException
-
getRequiredAttributeValue
public static String getRequiredAttributeValue(XmlPullParser pp, String namespace, String name) throws IOException, XmlPullParserException
Read attribute value and return it or throw exception if current element does not have such attribute.- Throws:
IOExceptionXmlPullParserException
-
nextEndTag
public static void nextEndTag(XmlPullParser pp) throws XmlPullParserException, IOException
Call parser nextTag() and check that it is END_TAG, throw exception if not.- Throws:
XmlPullParserExceptionIOException
-
matches
public static boolean matches(XmlPullParser pp, int type, String namespace, String name) throws XmlPullParserException
Tests if the current event is of the given type and if the namespace and name match. null will match any namespace and any name. If the test passes a true is returned otherwise a false is returned.- Throws:
XmlPullParserException
-
writeSimpleElement
public static void writeSimpleElement(XmlSerializer serializer, String namespace, String elementName, String elementText) throws IOException, XmlPullParserException
Writes a simple element such asjohndoe . The namespace and elementText are allowed to be null. If elementText is null, an xsi:nil="true" will be added as an attribute.- Throws:
IOExceptionXmlPullParserException
-
-