1

I have implemented XML Pull Parser for local XML file stored in Assets. I need to implement the same for XML in some destinated URL, how to pass URL to XML Pull parser?

Thnks

1
  • With VTD-XML, it is just calling parseHTTPURL from vtdGen, in two lines. Does your app require pull? Commented Mar 24, 2011 at 7:34

1 Answer 1

3
public static void getAllXML(String url) throws 

XmlPullParserException, IOException, URISyntaxException{ 

  XmlPullParserFactory factory = XmlPullParserFactory.newInstance();

  factory.setNamespaceAware(true);

  XmlPullParser parser = factory.newPullParser(); 

  parser.setInput(new InputStreamReader(getUrlData(url)));  

  XmlUtils.beginDocument(parser,"results");

  int eventType = parser.getEventType();

  do{

    XmlUtils.nextElement(parser);

    parser.next();

    eventType = parser.getEventType();

    if(eventType == XmlPullParser.TEXT){

      Log.d("test",parser.getText());

    }

  } while (eventType != XmlPullParser.END_DOCUMENT) ;       

}

public InputStream getUrlData(String url) 

throws URISyntaxException, ClientProtocolException, IOException {

  DefaultHttpClient client = new DefaultHttpClient();

  HttpGet method = new HttpGet(new URI(url));

  HttpResponse res = client.execute(method);

  return  res.getEntity().getContent();

}
Sign up to request clarification or add additional context in comments.

1 Comment

XmlUtils? where is it from?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.