13 Replies - 5853 Views - Last Post: 12 July 2010 - 11:16 AM Rate Topic: -----

#1 Matamane   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 12-August 09

Help With XML Pull Parser

Posted 11 July 2010 - 06:19 PM

I've recently learned about XMLPullParser, and I am interested in learning how to implement it.

Does anyone know of any source code or examples of the implementation I could look at?
Is This A Good Question/Topic? 0
  • +

Replies To: Help With XML Pull Parser

#2 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3213
  • View blog
  • Posts: 19,241
  • Joined: 14-September 07

Re: Help With XML Pull Parser

Posted 11 July 2010 - 06:21 PM

Here might be a good place to start. Looks nearly identical to StaX, which I wrote about yesterday.
Was This Post Helpful? 1
  • +
  • -

#3 Matamane   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 12-August 09

Re: Help With XML Pull Parser

Posted 11 July 2010 - 06:25 PM

It's the API I have been having trouble understanding, but your article was a huge help. What an odd coincidence, and quite fortunate. Thanks

So if I am understanding this correctly.

I initialize the XmlPullParserFactory as well as a Reader, and then I load an Xml file, and from there I can read from it.

This post has been edited by Matamane: 11 July 2010 - 06:40 PM

Was This Post Helpful? 0
  • +
  • -

#4 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3213
  • View blog
  • Posts: 19,241
  • Joined: 14-September 07

Re: Help With XML Pull Parser

Posted 11 July 2010 - 06:42 PM

Yup, that's about it.
Was This Post Helpful? 0
  • +
  • -

#5 Matamane   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 12-August 09

Re: Help With XML Pull Parser

Posted 11 July 2010 - 06:47 PM

View PostKYA, on 11 July 2010 - 05:42 PM, said:

Yup, that's about it.



So part 2.

import java.io.IOException;
 import java.io.StringReader;

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

 public class SimpleXmlPullApp
 {

     public static void main (String args[])
         throws XmlPullParserException, IOException
     {
         XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
         factory.setNamespaceAware(true);
         XmlPullParser xpp = factory.newPullParser();

         xpp.setInput( new StringReader ( "<foo>Hello World!</foo>" ) );
         int eventType = xpp.getEventType();
         while (eventType != XmlPullParser.END_DOCUMENT) {
          if(eventType == XmlPullParser.START_DOCUMENT) {
              System.out.println("Start document");
          } else if(eventType == XmlPullParser.END_DOCUMENT) {
              System.out.println("End document");
          } else if(eventType == XmlPullParser.START_TAG) {
              System.out.println("Start tag "+xpp.getName());
          } else if(eventType == XmlPullParser.END_TAG) {
              System.out.println("End tag "+xpp.getName());
          } else if(eventType == XmlPullParser.TEXT) {
              System.out.println("Text "+xpp.getText());
          }
          eventType = xpp.next();
         }
     }
 }



I'm getting the following error

/META-INF/services/org.xmlpull.v1.XmlPullParserFactory make sure that parser implementing XmlPull API is available

How do I fix this.

c
Was This Post Helpful? 0
  • +
  • -

#6 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3213
  • View blog
  • Posts: 19,241
  • Joined: 14-September 07

Re: Help With XML Pull Parser

Posted 11 July 2010 - 06:50 PM

Do you have the appropriate JARs/libraries added to your project?
Was This Post Helpful? 0
  • +
  • -

#7 Matamane   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 12-August 09

Re: Help With XML Pull Parser

Posted 11 July 2010 - 06:54 PM

The folders are in the same project.

Do I have to add the JAR to my libraries instead?
Was This Post Helpful? 0
  • +
  • -

#8 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3213
  • View blog
  • Posts: 19,241
  • Joined: 14-September 07

Re: Help With XML Pull Parser

Posted 11 July 2010 - 07:22 PM

I'm almost 100% positive that's what you need to do (I haven't tested it myself otherwise I could tell you for sure).
Was This Post Helpful? 0
  • +
  • -

#9 Matamane   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 12-August 09

Re: Help With XML Pull Parser

Posted 12 July 2010 - 03:47 AM

I got it working, now I am trying to load from a uri. What reader would you suggest?
Was This Post Helpful? 0
  • +
  • -

#10 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3213
  • View blog
  • Posts: 19,241
  • Joined: 14-September 07

Re: Help With XML Pull Parser

Posted 12 July 2010 - 07:21 AM

XMLStreamReader...should be compatible with this pull API?
Was This Post Helpful? 0
  • +
  • -

#11 Matamane   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 12-August 09

Re: Help With XML Pull Parser

Posted 12 July 2010 - 10:59 AM

View PostKYA, on 12 July 2010 - 06:21 AM, said:

XMLStreamReader...should be compatible with this pull API?


Not exactly, which is why I was asking. But I thought up an odd bit of necromancy which would allow it too. I am testing it now
Was This Post Helpful? 0
  • +
  • -

#12 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3213
  • View blog
  • Posts: 19,241
  • Joined: 14-September 07

Re: Help With XML Pull Parser

Posted 12 July 2010 - 11:01 AM

Doesn't look like you need a "reader" (like the ones in the standard API). XMLPull's "reader" is called "XMLPullParser". See here.
Was This Post Helpful? 0
  • +
  • -

#13 Matamane   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 111
  • Joined: 12-August 09

Re: Help With XML Pull Parser

Posted 12 July 2010 - 11:12 AM

setInput takes either a Reader, or both an InputStream and String.

I tried to initialize an XMLReader using a sub factory of XMLInputFactory.

That failed.

using a URL.openStream and a null string worked fine.
Was This Post Helpful? 0
  • +
  • -

#14 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3213
  • View blog
  • Posts: 19,241
  • Joined: 14-September 07

Re: Help With XML Pull Parser

Posted 12 July 2010 - 11:16 AM

I misunderstood the question. There's no reason to use an XMLStreamReader here. :stupid:

What you pass in depends on your source (like the URL) you mentioned or a file on your local drive, etc...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1