• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XML Parsing problems

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there
I am currently experiencing problems when trying to read in an xml document that I am working on:-

Now, if I use this xml document the code will not run :-

The code will only work if the nodes are written on one line each in the file as shown :-

Anyone know why this is? I tried editing the file in different editors but it made no difference.
Alex
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey that sounds familiar! I got bit by this one before. When you put each element on a separate line, there is actually a Text Node created so getFirstChild() gets a Text node consisting of <cr><lf> and some spaces or tabs.
You need to either get the child nodelist and work through it to find the one you want or create the parser so that it ignores this "ignorable whitespace".
DocumentBuilderFactory has a setIgnoringElementContentWhitespace( true )
method which I think is what you want (but I have not tried it.)
Bill
 
Alex Ioannou
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there
I see what you mean with the text tags. I scanned through the entire noadlist and found that there were double the amount of entries that I was expecting!!!
I did a check on each node seeing if it had any children, then I pulled out the values I wanted.
I think I'll be using

a lot more in future to narrow down the nodes before retrieving the values from them.
Alex
 
reply
    Bookmark Topic Watch Topic
  • New Topic