Android XmlPullParserFactory - 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 XmlPullParserFactory class.

This code example shows how to use the following methods: newPullParser
    String filename = attributes.get("filename");
    if (filename == null) {
      return; 
    } 
 
    Schema niftyXmlSchema = new Schema(parserFactory, resourceLoader);
    XmlParser parser = new XmlParser(parserFactory.newPullParser());
    InputStream stream = resourceLoader.getResourceAsStream(filename);
    if (stream != null) {
      try { 
        parser.read(stream);
        parser.nextTag();
        parser.required("nxs", niftyXmlSchema);
 
        types.putAll(niftyXmlSchema.getTypes());
        xmlParser.nextTag();
      } finally { 
        try { 
          stream.close();
        } catch (IOException ignored) {}
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setNamespaceAware, setValidating
    try { 
      parserFactory = XmlPullParserFactory.newInstance();
    } catch (XmlPullParserException e) {
      throw new RuntimeException("Failure to load the XmlPullParser, something is badly wrong!", e);
    } 
    parserFactory.setValidating(false);
    parserFactory.setNamespaceAware(true);
    this.nifty = nifty;
    this.timeProvider = timeProvider;
  } 
 
  /** 
   * Load a Nifty-GUI XML file and get the type that is defined in the file. The XML file needs to be a valid XML GUI 
   * definition. 
   * 
   * @param schemaId       the name of the schema that should be used to validate the XML file 
   * @param inputStreamXml the input stream of the XML file, this stream <b>will be closed</b> by this function 
   * @return the NiftyType that was load from the XML file 
   * @throws Exception in case the loading fails at any point 
   */ 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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());
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
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);
        } 
    } 
} 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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);
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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);
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: attribute
    } 
 
    private static class MySerializer implements XmlSerializerAndParser<AuthenticatorDescription> {
        public void writeAsXml(AuthenticatorDescription item, XmlSerializer out)
                throws IOException { 
            out.attribute(null, "type", item.type);
        } 
 
        public AuthenticatorDescription createFromXml(XmlPullParser parser)
                throws IOException, XmlPullParserException { 
            return AuthenticatorDescription.newKey(parser.getAttributeValue(null, "type"));
        } 
    } 
} 
Full Snippet Info
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android XmlPullParserFactory Questions & Answers:

Other Android XmlPullParserFactory Examples

11:	         throws XmlPullParserException, IOException
12:	     {
13:	         XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
14:	         factory.setNamespaceAware(true);
15:	         XmlPullParser xpp = factory.newPullParser();

Read More

See Code Examples for Android XmlPullParserFactory Methods: