XmlPullParser next - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for XmlPullParser next method.

This code example shows how to use the following methods:getAttributeValue, next, setInput
        assertParseFailure("<foo a='<'></foo>"); 
    } 
 
    public void testQuotesInAttribute() throws Exception{ 
        XmlPullParser parser = newPullParser();
        parser.setInput(new StringReader("<foo a='\"' b=\"'\"></foo>"));
        assertEquals(XmlPullParser.START_TAG, parser.next());
        assertEquals("\"", parser.getAttributeValue(0));
        assertEquals("'", parser.getAttributeValue(1));
    } 
 
    public void testQuotesInText() throws Exception{ 
        XmlPullParser parser = newPullParser();
        parser.setInput(new StringReader("<foo>\" '</foo>"));
        assertEquals(XmlPullParser.START_TAG, parser.next());
        assertEquals(XmlPullParser.TEXT, parser.next());
        assertEquals("\" '", parser.getText());
    } 
 
    public void testCdataDelimiterInAttribute() throws Exception{ 
7
CodeRank
This code example shows how to use the following methods:getName, getText, next, nextToken, setInput
    } 
 
    public void testDoctypeWithNextToken() throws Exception { 
        String xml = "<!DOCTYPE foo [<!ENTITY bb \"bar baz\">]><foo>a&bb;c</foo>";
        XmlPullParser parser = newPullParser(xml);
        assertEquals(XmlPullParser.DOCDECL, parser.nextToken());
        assertEquals(" foo [<!ENTITY bb \"bar baz\">]", parser.getText());
        assertNull(parser.getName());
        assertEquals(XmlPullParser.START_TAG, parser.nextToken());
        assertEquals(XmlPullParser.TEXT, parser.next());
        assertEquals("abar bazc", parser.getText());
        assertEquals(XmlPullParser.END_TAG, parser.next());
        assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
    } 
 
    public void testDoctypeSpansBuffers() throws Exception { 
        char[] doctypeChars = new char[READ_BUFFER_SIZE + 1];
        Arrays.fill(doctypeChars, 'x');
        String doctypeBody = " foo [<!--" + new String(doctypeChars) + "-->]";
        String xml = "<!DOCTYPE" + doctypeBody + "><foo/>";

7
CodeRank
This code example shows how to use the following methods:getName, getText, next, setInput
                + "<!ENTITY example \"<p>An ampersand (&#38;#38;) may be escaped\n" 
                + "numerically (&#38;#38;#38;) or with a general entity\n" 
                + "(&amp;amp;).</p>\" >" 
                + "]><foo>&example;</foo>"; 
        XmlPullParser parser = newPullParser(xml);
        assertEquals(XmlPullParser.START_TAG, parser.next());
        assertEquals(XmlPullParser.START_TAG, parser.next());
        assertEquals("p", parser.getName());
        assertEquals(XmlPullParser.TEXT, parser.next());
        assertEquals("An ampersand (&) may be escaped\n"
                + "numerically (&#38;) or with a general entity\n" 
                + "(&amp;).", parser.getText());
        assertEquals(XmlPullParser.END_TAG, parser.next());
        assertEquals("p", parser.getName());
        assertEquals(XmlPullParser.END_TAG, parser.next());
        assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
    } 
 
    public void testGeneralEntitiesAreStoredUnresolved() throws Exception { 
        String xml = "<!DOCTYPE foo ["

7
CodeRank
This code example shows how to use the following methods:getName, getText, next, setFeature, setInput
        assertParseFailure("<foo>&aaa;</foo>"); 
    } 
 
    public void testMissingEntitiesWithRelaxed() throws Exception { 
        XmlPullParser parser = newPullParser();
        parser.setFeature("http://xmlpull.org/v1/doc/features.html#relaxed", true);
        parser.setInput(new StringReader("<foo>&aaa;</foo>"));
        assertEquals(XmlPullParser.START_TAG, parser.next());
        assertEquals(XmlPullParser.TEXT, parser.next());
        assertEquals(null, parser.getName());
        assertEquals("Expected unresolved entities to be left in-place. The old parser "
                + "would resolve these to the empty string.", "&aaa;", parser.getText());
        assertEquals(XmlPullParser.END_TAG, parser.next());
    } 
 
    public void testMissingEntitiesUsingNextToken() throws Exception { 
        XmlPullParser parser = newPullParser();
        testMissingEntitiesUsingNextToken(parser);
    } 
 
6
CodeRank
This code example shows how to use the following methods:getLineNumber, isWhitespace, next
    public String getText() {
        return mParser.getText();
    } 
 
    public int getLineNumber() { 
        return mParser.getLineNumber();
    } 
 
    public int getEventType() { 
        return mEventType;
    } 
 
    public boolean isWhitespace() throws XmlPullParserException { 
        // Original comment: whitespace was stripped by aapt. 
        return mParser.isWhitespace();
    } 
 
    public String getPrefix() {
        throw new RuntimeException("getPrefix not supported");
    } 

6
CodeRank
This code example shows how to use the following methods:getText, next, nextTag, require
        return link;
    } 
 
    // Processes summary tags in the feed. 
    private String readSummary(XmlPullParser parser) throws IOException, XmlPullParserException {
        parser.require(XmlPullParser.START_TAG, ns, "summary");
        String summary = readText(parser);
        parser.require(XmlPullParser.END_TAG, ns, "summary");
        return summary;
    } 
 
    // For the tags title and summary, extracts their text values. 
    private String readText(XmlPullParser parser) throws IOException, XmlPullParserException {
        String result = "";
        if (parser.next() == XmlPullParser.TEXT) {
            result = parser.getText();
            parser.nextTag();
        } 
        return result;
    } 

7
CodeRank

Related XmlPullParser next Questions & Answers:

Other XmlPullParser next Examples

29:	              System.out.println("Text "+xpp.getText());
30:	          }
31:	          eventType = xpp.next();
32:	         }
33:	     }

Read More

next Method Overview
Get next parsing event - element content wil 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 mus be thrown if entity reference can not be expanded).
See Code Examples for other Android XmlPullParser Methods: