org.xmlpull.v1.util
Class XmlPullUtil

java.lang.Object
  extended by org.xmlpull.v1.util.XmlPullUtil

public class XmlPullUtil
extends java.lang.Object

Handy functions that combines XmlPull API into higher level functionality.


Field Summary
static java.lang.String XSI_NS
           
 
Method Summary
static java.lang.String getAttributeValue(XmlPullParser pp, java.lang.String name)
          Return value of attribute with given name and no namespace.
static java.lang.String getPIData(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 ::= '<?'
static java.lang.String getPITarget(XmlPullParser pp)
          Return PITarget from Processing Instruction (PI) as defined in XML 1.0 Section 2.6 Processing Instructions [16] PI ::= '<?'
static java.lang.String getRequiredAttributeValue(XmlPullParser pp, java.lang.String namespace, java.lang.String name)
          Read attribute value and return it or throw exception if current element does not have such attribute.
static boolean matches(XmlPullParser pp, int type, java.lang.String namespace, java.lang.String name)
          Tests if the current event is of the given type and if the namespace and name match.
static void nextEndTag(XmlPullParser pp)
          Call parser nextTag() and check that it is END_TAG, throw exception if not.
static void nextEndTag(XmlPullParser pp, java.lang.String namespace, java.lang.String name)
          combine nextTag(); pp.require(XmlPullParser.END_TAG, namespace, name);
static void nextStartTag(XmlPullParser pp)
          call parser nextTag() and check that it is START_TAG, throw exception if not.
static void nextStartTag(XmlPullParser pp, java.lang.String name)
          combine nextTag(); pp.require(XmlPullParser.START_TAG, null, name);
static void nextStartTag(XmlPullParser pp, java.lang.String namespace, java.lang.String name)
          combine nextTag(); pp.require(XmlPullParser.START_TAG, namespace, name);
static java.lang.String nextText(XmlPullParser pp, java.lang.String namespace, java.lang.String name)
          Read text content of element ith given namespace and name (use null namespace do indicate that nemspace should not be checked)
static void skipSubTree(XmlPullParser pp)
          Skip sub tree that is currently porser positioned on.
static void writeSimpleElement(XmlSerializer serializer, java.lang.String namespace, java.lang.String elementName, java.lang.String elementText)
          Writes a simple element such as johndoe.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XSI_NS

public static final java.lang.String XSI_NS
See Also:
Constant Field Values
Method Detail

getAttributeValue

public static java.lang.String getAttributeValue(XmlPullParser pp,
                                                 java.lang.String name)
Return value of attribute with given name and no namespace.


getPITarget

public static java.lang.String getPITarget(XmlPullParser pp)
                                    throws java.lang.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:
java.lang.IllegalStateException

getPIData

public static java.lang.String getPIData(XmlPullParser pp)
                                  throws java.lang.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:
java.lang.IllegalStateException

skipSubTree

public static void skipSubTree(XmlPullParser pp)
                        throws XmlPullParserException,
                               java.io.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:
XmlPullParserException
java.io.IOException

nextStartTag

public static void nextStartTag(XmlPullParser pp)
                         throws XmlPullParserException,
                                java.io.IOException
call parser nextTag() and check that it is START_TAG, throw exception if not.

Throws:
XmlPullParserException
java.io.IOException

nextStartTag

public static void nextStartTag(XmlPullParser pp,
                                java.lang.String name)
                         throws XmlPullParserException,
                                java.io.IOException
combine nextTag(); pp.require(XmlPullParser.START_TAG, null, name);

Throws:
XmlPullParserException
java.io.IOException

nextStartTag

public static void nextStartTag(XmlPullParser pp,
                                java.lang.String namespace,
                                java.lang.String name)
                         throws XmlPullParserException,
                                java.io.IOException
combine nextTag(); pp.require(XmlPullParser.START_TAG, namespace, name);

Throws:
XmlPullParserException
java.io.IOException

nextEndTag

public static void nextEndTag(XmlPullParser pp,
                              java.lang.String namespace,
                              java.lang.String name)
                       throws XmlPullParserException,
                              java.io.IOException
combine nextTag(); pp.require(XmlPullParser.END_TAG, namespace, name);

Throws:
XmlPullParserException
java.io.IOException

nextText

public static java.lang.String nextText(XmlPullParser pp,
                                        java.lang.String namespace,
                                        java.lang.String name)
                                 throws java.io.IOException,
                                        XmlPullParserException
Read text content of element ith given namespace and name (use null namespace do indicate that nemspace should not be checked)

Throws:
java.io.IOException
XmlPullParserException

getRequiredAttributeValue

public static java.lang.String getRequiredAttributeValue(XmlPullParser pp,
                                                         java.lang.String namespace,
                                                         java.lang.String name)
                                                  throws java.io.IOException,
                                                         XmlPullParserException
Read attribute value and return it or throw exception if current element does not have such attribute.

Throws:
java.io.IOException
XmlPullParserException

nextEndTag

public static void nextEndTag(XmlPullParser pp)
                       throws XmlPullParserException,
                              java.io.IOException
Call parser nextTag() and check that it is END_TAG, throw exception if not.

Throws:
XmlPullParserException
java.io.IOException

matches

public static boolean matches(XmlPullParser pp,
                              int type,
                              java.lang.String namespace,
                              java.lang.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,
                                      java.lang.String namespace,
                                      java.lang.String elementName,
                                      java.lang.String elementText)
                               throws java.io.IOException,
                                      XmlPullParserException
Writes a simple element such as johndoe. The namespace and elementText are allowed to be null. If elementText is null, an xsi:nil="true" will be added as an attribute.

Throws:
java.io.IOException
XmlPullParserException