Android XmlPullParserException - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android XmlPullParserException class.

This code example shows how to use the following methods:
                outBundle.putInt(name, v.data);
            } else if (v.type == TypedValue.TYPE_FLOAT) {
                outBundle.putFloat(name, v.getFloat());
            } else { 
                sa.recycle();
                throw new XmlPullParserException("<" + tagName
                        + "> only supports string, integer, float, color, and boolean at " 
                        + attrs.getPositionDescription());
            } 
        } else { 
            sa.recycle();
            throw new XmlPullParserException("<" + tagName
                    + "> requires an holo:value attribute at " + attrs.getPositionDescription());
        } 
        sa.recycle();
    } 
 
    private static Intent parseIntent(Resources resources, XmlPullParser parser, AttributeSet attrs)
            throws XmlPullParserException, IOException { 
        Intent intent = new Intent();
7
CodeRank
This code example shows how to use the following methods:getMessage, getColumnNumber, getDetail, getLineNumber
7
CodeRank
This code example shows how to use the following methods:attribute, endTag, startTag, text
 
    private void addProblem(String tag, Throwable error) {
        try { 
            recordTestTime(); 
 
            mSerializer.startTag("", tag);
            mSerializer.attribute("", ATTRIBUTE_MESSAGE, safeMessage(error));
            mSerializer.attribute("", ATTRIBUTE_TYPE, error.getClass().getName());
            StringWriter w = new StringWriter();
            error.printStackTrace(mFilterTraces ? new FilteringWriter(w) : new PrintWriter(w));
            mSerializer.text(w.toString());
            mSerializer.endTag("", tag);
        } catch (IOException e) {
            Log.e(LOG_TAG, safeMessage(e));
        } 
    } 
 
    private void recordTestTime() throws IOException { 
        if (!mTimeAlreadyWritten) {
            mTimeAlreadyWritten = true;

9
CodeRank
This code example shows how to use the following methods:getText, next, nextToken, setInput
        assertParseFailure("<foo><!-- -- --></foo>"); 
    } 
 
    public void testEmptyComment() throws Exception { 
        XmlPullParser parser = newPullParser();
        parser.setInput(new StringReader("<foo><!----></foo>"));
        assertEquals(XmlPullParser.START_TAG, parser.next());
        assertEquals(XmlPullParser.COMMENT, parser.nextToken());
        assertEquals("", parser.getText());
    } 
 
    /** 
     * Close braces require lookaheads because we need to defend against "]]>". 
     */ 
    public void testManyCloseBraces() 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());
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:endDocument, endTag, flush
        return super.onException(obj, thr);
    } 
 
    void endTestSuites() { 
        try { 
            mTestSuiteSerializer.endTag(null, "testsuites");
            mTestSuiteSerializer.endDocument();
            mTestSuiteSerializer.flush();
 
            mWriter.flush();
            mWriter.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:attribute, endTag, startTag
    } 
 
    private static void serializeFeedUrl(XmlSerializer serializer,
            FeedUrl feedUrl)
            throws IOException { 
        serializer.startTag(NAMESPACE_GSYNC_URI, "feedurl");
        serializer.attribute(null /* ns */, "value", feedUrl.getFeed());
        serializer.attribute(null /* ns */, "service", feedUrl.getService());
        serializer.attribute(null /* ns */, "authtoken", feedUrl.getAuthToken());
        serializer.endTag(NAMESPACE_GSYNC_URI, "feedurl");
    } 
 
    private static void serializeClientToken(XmlSerializer serializer,
            String clientToken)
            throws IOException { 
        if (StringUtils.isEmpty(clientToken)) {
            clientToken = "";
        } 
        serializer.startTag(NAMESPACE_GSYNC_URI, "clientToken");
        serializer.text(clientToken);
7
CodeRank
This code example shows how to use the following methods:flush, setFeature, setOutput
 
    private String nodeToNormalizedString(Node node)
            throws XmlPullParserException, IOException { 
        StringWriter writer = new StringWriter();
        XmlSerializer xmlSerializer = xmlPullParserFactory.newSerializer();
        xmlSerializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        xmlSerializer.setOutput(writer);
        emitNode(xmlSerializer, node);
        xmlSerializer.flush();
        return writer.toString();
    } 
 
    private void emitNode(XmlSerializer serializer, Node node) throws IOException {
        if (node == null) {
            throw new UnsupportedOperationException("Cannot emit null nodes");
 
        } else if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element element = (Element) node;
            serializer.startTag(element.getNamespaceURI(), element.getLocalName());
            emitAttributes(serializer, element);
7
CodeRank
This code example shows how to use the following methods:getMessage
parser.setInput(input, "UTF-8"); //$NON-NLS-1$
 
            return parse(type, path, parser);
        } catch (XmlPullParserException e) {
            String message = e.getMessage();
 
            // Strip off position description 
            int index = message.indexOf("(position:"); //$NON-NLS-1$ (Hardcoded in KXml)
            if (index != -1) {
                message = message.substring(0, index);
            } 
 
            String error = String.format("%1$s:%2$d: Error: %3$s", //$NON-NLS-1$
                    path, parser.getLineNumber(), message);
            mContext.addError(error);
            return false; 
        } catch (RuntimeException e) {
            // Some exceptions are thrown by the KXmlParser that are not XmlPullParserExceptions, 
            // such as this one: 
6
CodeRank
This code example shows how to use the following methods:getName, getText, next, nextToken, setInput
    } 
 
    public void testStructuredEntityAndNextToken() throws Exception { 
        String xml = "<!DOCTYPE foo [<!ENTITY bb \"<bar>baz<!--quux--></bar>\">]><foo>a&bb;c</foo>";
        XmlPullParser parser = newPullParser(xml);
        assertEquals(XmlPullParser.DOCDECL, parser.nextToken());
        assertEquals(XmlPullParser.START_TAG, parser.nextToken());
        assertEquals("foo", parser.getName());
        assertEquals(XmlPullParser.TEXT, parser.nextToken());
        assertEquals("a", parser.getText());
        assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken());
        assertEquals("bb", parser.getName());
        assertEquals("", parser.getText());
        assertEquals(XmlPullParser.START_TAG, parser.nextToken());
        assertEquals("bar", parser.getName());
        assertEquals(XmlPullParser.TEXT, parser.nextToken());
        assertEquals("baz", parser.getText());
        assertEquals(XmlPullParser.COMMENT, parser.nextToken());
        assertEquals("quux", parser.getText());
        assertEquals(XmlPullParser.END_TAG, parser.nextToken());

8
CodeRank

Related Android XmlPullParserException Questions & Answers:

See Code Examples for Android XmlPullParserException Methods: