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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE

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: