Android XmlPullParser Value Get getPIData(XmlPullParser pp)

Here you can find the source of getPIData(XmlPullParser pp)

Description

Return everything past PITarget and S from Processing Instruction (PI) as defined in XML 1.0 Section 2.6 Processing Instructions [16] PI ::= '<?'

Declaration

public static String getPIData(XmlPullParser pp)
        throws IllegalStateException 

Method Source Code

//package com.java2s;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

public class Main {
    /**// w w w  .  ja v  a  2 s . co  m
     * Return everything past PITarget and S from Processing Instruction (PI) as defined in
     * XML 1.0 Section 2.6 Processing Instructions
     *  <code>[16] PI ::= '&lt;?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'</code>
     *
     * <p><b>NOTE:</b> if there is no PI data it returns empty string.
     */
    public static String getPIData(XmlPullParser pp)
            throws IllegalStateException {
        int eventType;
        try {
            eventType = pp.getEventType();
        } catch (XmlPullParserException ex) {
            // should never happen ...
            throw new IllegalStateException(
                    "could not determine parser state: " + ex
                            + pp.getPositionDescription());
        }
        if (eventType != XmlPullParser.PROCESSING_INSTRUCTION) {
            throw new IllegalStateException(
                    "parser must be on processing instruction and not "
                            + XmlPullParser.TYPES[eventType]
                            + pp.getPositionDescription());
        }
        final String PI = pp.getText();
        int pos = -1;
        for (int i = 0; i < PI.length(); i++) {
            if (isS(PI.charAt(i))) {
                pos = i;
            } else if (pos > 0) {
                return PI.substring(i);
            }
        }
        return "";

    }

    /**
     * Return true if chacters is S as defined in XML 1.0
     * <code>S ::=  (#x20 | #x9 | #xD | #xA)+</code>
     */
    private static boolean isS(char ch) {
        return (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t');
    }
}

Related

  1. getAttributeByName(XmlPullParser xpp, String name)
  2. getAttributeValue(XmlPullParser pp, String name)
  3. getAttributeValue(XmlPullParser pp, String name)
  4. getAttributes( XmlPullParser pullParser)
  5. getAttributes( XmlPullParser pullParser, String namespace, String elementName, String attributeName, String attributeValue)
  6. getPIData(XmlPullParser pp)
  7. getPITarget(XmlPullParser pp)
  8. getPITarget(XmlPullParser pp)
  9. getRequiredAttributeValue(XmlPullParser pp, String namespace, String name)