[Solved]XML DOM parsing issue

Put your problem here if it does not fit any of the other categories.

[Solved]XML DOM parsing issue

Postby bibiodp » Tue Dec 18, 2007 3:40 pm

Hello,

I'm trying to parse an xml on a remote server and it seems that it's not possible to do this in the xmpp way :
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. this.getResources().getXml(id)
  3.  
  4.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4

because I don't know which id to use.

So I tried in the DOM way. My remote XML document looks like this (quite simple for now):
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <root>
  3.  
  4.   <title>My title</title>
  5.  
  6. </root>
  7.  
  8.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4



and here is the code to parse it :
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  3.  
  4. Document doc = db.parse(new URL(filePath).openStream());
  5.  
  6. doc.normalize();
  7.  
  8. Element root = doc.getDocumentElement();
  9.  
  10. NodeList nodes = root.getChildNodes();
  11.  
  12. for (int i = 0; i < nodes.getLength(); i++) {
  13.  
  14.   if (nodes.item(i).getNodeName().equalsIgnoreCase("title")){
  15.  
  16.     Log.i(ParserBase.class.toString(),"title : " + nodes.item(i).getNodeValue());
  17.  
  18.   }
  19.  
  20. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4



When I loot at the logs my title is null. It means that it found the <title> tag but i can't manage to get the value...

Does somebody see the problem?

Thx :)
Last edited by bibiodp on Wed Dec 19, 2007 9:48 am, edited 1 time in total.
I'm a poor lonesome French developper ;)
bibiodp
Junior Developer
Junior Developer
 
Posts: 12
Joined: Mon Nov 26, 2007 6:18 pm

Top

Postby lordhong » Tue Dec 18, 2007 10:18 pm

:shock: yes, i had the same problem so i gave up on dom, but use SAX parser instead...
lordhong
Developer
Developer
 
Posts: 42
Joined: Thu Nov 22, 2007 5:25 am
Location: New York

Postby plusminus » Tue Dec 18, 2007 10:51 pm

Hello bibiodp,

perhaps this Thread helps: :src: http://www.anddev.org/viewtopic.php?p=940#940

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby bibiodp » Wed Dec 19, 2007 9:33 am

Thx for replying.

@plusminus : I saw this thread and that's the one I started from.

@lordhong : I tried to use SAX but the only way I know is to extend the ContentHandler class but it seems it's missing in Android API. How did you make it work?
I'm a poor lonesome French developper ;)
bibiodp
Junior Developer
Junior Developer
 
Posts: 12
Joined: Mon Nov 26, 2007 6:18 pm

Postby bibiodp » Wed Dec 19, 2007 9:48 am

OK I think I found here : http://www.anddev.org/viewtopic.php?t=318

I'll extend the DefaultHandler class.

THx for all :)
I'm a poor lonesome French developper ;)
bibiodp
Junior Developer
Junior Developer
 
Posts: 12
Joined: Mon Nov 26, 2007 6:18 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 11 guests