0

I am getting some xml from the web, and like this

XmlPullParser receivedData = XmlPullParserFactory.newInstance().newPullParser();
receivedData.setInput(xmlUrl.openStream(), null);

And I want to set the receivedData to a readable string so I can check if the xml on the web is the same as what I am downloading.

I tried receivedData.toString() But this just gives, org.kxml2.io.KXmlParser@27fd33b24

how can I get a readable string?

Thanks

spen123
  • 2,934
  • 10
  • 34
  • 50

2 Answers2

0

The toString() method is returning the java object reference as the java.lang.Object's toString method does. This method is not overriden by the XmlPullParser class.

I am not really sure about how is working the XmlPullParser object works, but it seems to be an event-oriented XML parser. You may add some logs to display your events while parsing the XML using the getText method on a node.

The server's content may also be intercepted before to instantiate the XmlPullParser object; I don't know what is the exact implementation of InputStream you are receiving from "xmlUrl.openStream()" but you can try to stringify it with the IOUtils classes like this:

String theString = IOUtils.toString(inputStream, encoding);

See this post

Community
  • 1
  • 1
Francois Gergaud
  • 266
  • 2
  • 11
  • what is IOUtils, I don't have that as an import? – spen123 Jul 07 '15 at 21:24
  • IOUtils is a set of utility class which help to manipulate streams and other stuffs. It is not part of the JDK, you must add the jar to your project to be able to use it. If you work with maven, you can import this artifact with the information provided on this page: http://mvnrepository.com/artifact/org.apache.commons/commons-io/1.3.2 (the last stable version available when I am writing this comment). On this same page you can also find a link to download the jar and put it in your project if you prefer to manage your dependencies "by hand". – Francois Gergaud Jul 09 '15 at 04:49
0

Unfortunately, XmlPullParser doesn't override toString method , what you saw here is the string representation of this object. It means it has been created in the mem. Hence, it doesn't provide in depth details of this class. But you have two ways to get information that you may need from this class.

  1. you can set break point in your ide at line that this instance has been created and step into it for the details of this class through the debugger.

  2. OR you can go to http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html see what public get method this class has and programmaticly print out those details.

Jegg
  • 541
  • 3
  • 11