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 :

parsing_xml_from_the_net_-_using_the_saxparser-t353.html

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=http://prestacionesrh50.safp.cl/garest_web/files/102/xml/ge_resolucion200811.xml&url_salida=http://prestacionesrh50.safp.cl/garest_web/generar_resoluciones/recibe_resolucion_firmada.php?idu=102&aaaamm=200811&url_retorno=http://prestacionesrh50.safp.cl/garest_web/generar_resoluciones/resolucion_firmada.php?idu=102");
  2.  
  3. SAXParserFactory spf = SAXParserFactory.newInstance();
  4.                 SAXParser sp = spf.newSAXParser();
  5.  
  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);
  11.                        
  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);
  16.                  
  17.                 /* Parsing has finished. */
  18.  
  19.                 /* Our ExampleHandler now provides the parsed data to us. */
  20.                 MyParsedDataSet parsedDataSet = Handler.getParsedData();
  21.  
  22.                 /* Set the result to be displayed in our GUI. */
  23.                 tv.setText(parsedDataSet.toString());
  24.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


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.

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

Top

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
kartik_trivedi
Developer
Developer
 
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.

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

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: Exabot [Bot] and 5 guests