Parsing XML from the net

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Parsing XML from the net

Postby Helios » Tue Jan 27, 2009 7:23 pm

Hi, I am trying to parse a XML from a url using the tutorial that is found in the tutorial section in :


For this the class and URL that I'm using is defined as it follows:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  URL url = new URL("http://testing:8082/firma/FirmaServlet?comando=iniciar_proceso&nombre=nombreDelDocumento&proceso=4&url_entrada=");
  3. SAXParserFactory spf = SAXParserFactory.newInstance();
  4.                 SAXParser sp = spf.newSAXParser();
  6.                 /* Get the XMLReader of the SAXParser we created. */
  7.                 XMLReader xr = sp.getXMLReader();
  8.                 /* Create a new ContentHandler and apply it to the XML-Reader*/
  9.                 MyHandler Handler = new MyHandler();
  10.                 xr.setContentHandler(Handler);
  12.                 /* Parse the xml-data from our URL. */
  13.                 InputStream stream_url = url.openStream();
  14.                 InputSource source_url = new InputSource (stream_url);
  15.                 xr.parse(source_url);
  17.                 /* Parsing has finished. */
  19.                 /* Our ExampleHandler now provides the parsed data to us. */
  20.                 MyParsedDataSet parsedDataSet = Handler.getParsedData();
  22.                 /* Set the result to be displayed in our GUI. */
  23.                 tv.setText(parsedDataSet.toString());
Parsed in 0.012 seconds, using GeSHi

I believe that my problem is that when I use url.openStream() it doesn't open it correctly and I don't know how to fix this. A weird thing is that I noticed is that if I open this url in my computer's browser (firefox) it shows me correctly de xml file, but if I open this link in the emulator's browser it shows a message saying that the web page is not available.

When I run my application the error message that it shows is "Host is unresolved". I hope some one could help me.

Junior Developer
Junior Developer
Posts: 23
Joined: Sat Jan 17, 2009 7:11 am


same xml parsing problem

Postby kartik_trivedi » Thu Jan 29, 2009 12:03 pm

I also face same problem. If our html page contains java scripts then it is creating exception. I hope some one will help me to solve this.
Sun Certified Java Developer
Forum Nokia Champion
Posts: 28
Joined: Tue Jan 20, 2009 7:19 am

Postby Helios » Thu Jan 29, 2009 2:47 pm

Hi, after searching a lot in the web I found no documented answer for this problem. The "solution" that I used to fix this problem came from opening the url on Android's browser and noticing that it generated an error. In my case I analyzed the URL I was handing and noticed that the server name was "testing" word that may be part of the browser "common language" so I change it for the server's ip and all worked perfectly. I hope this helps you to fix your problem.

Junior Developer
Junior Developer
Posts: 23
Joined: Sat Jan 17, 2009 7:11 am


Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 5 guests