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?
Help With XML Pull ParserWhere to begin
Page 1 of 1
13 Replies - 5853 Views - Last Post: 12 July 2010 - 11:16 AM
Replies To: Help With XML Pull Parser
#2
Re: Help With XML Pull Parser
Posted 11 July 2010 - 06:21 PM
#3
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.
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
#5
Re: Help With XML Pull Parser
Posted 11 July 2010 - 06:47 PM
KYA, 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
#6
Re: Help With XML Pull Parser
Posted 11 July 2010 - 06:50 PM
Do you have the appropriate JARs/libraries added to your project?
#7
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?
Do I have to add the JAR to my libraries instead?
#8
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).
#9
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?
#10
Re: Help With XML Pull Parser
Posted 12 July 2010 - 07:21 AM
XMLStreamReader...should be compatible with this pull API?
#11
Re: Help With XML Pull Parser
Posted 12 July 2010 - 10:59 AM
#13
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.
I tried to initialize an XMLReader using a sub factory of XMLInputFactory.
That failed.
using a URL.openStream and a null string worked fine.
#14
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.
What you pass in depends on your source (like the URL) you mentioned or a file on your local drive, etc...
What you pass in depends on your source (like the URL) you mentioned or a file on your local drive, etc...
Page 1 of 1

New Topic/Question
Reply



MultiQuote



|