• 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

Dom and empty nodes

 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am getting an xml String that has new lines and empty spaces between nodes. So for example if I am on root and I am saying root.getFirstChild() I am getting the text node that is new line and spaces instead of the real child.
I tried normalize on the root but it didn't help. What do I do?

thanks.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stop calling getFirstChild() if you don't want the first child. Do something else which gets the child you are interested in.

That could involve getting all the children and examining them, or calling getElementsByTagName, or using XPath, or something else.

Edit: and don't call the child you are interested in the "real" child. All of them are real. Calling it that just leads you into denial. The structure of the document is what it is. Choose what you want and ignore what you don't want.
[ December 11, 2008: Message edited by: Paul Clapham ]
 
John Landon
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
not helpful.
at the point of parsing I don't know any paths or names. I just know I need the "real" child
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, if you have no idea what you are looking for then you would be out of luck. Perhaps you should review your requirements. But I have a suspicion that you do know what you are looking for.

Let me guess: you're looking for an element?
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by John Landon:
not helpful.
at the point of parsing I don't know any paths or names. I just know I need the "real" child



You may not have read all of Paul's reply. He made another suggestion besides using paths or names:

Originally posted by Paul Clapham:
That could involve getting all the children and examining them, or...



Unfortunately

probably won't compile. But iterating through the NodeList until the current node is an instance of an Element would work.
[ December 11, 2008: Message edited by: Mark Vedder ]
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suggest somebody move this to our JavaScript forum.
 
John Landon
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys.
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rob Prime:
I suggest somebody move this to our JavaScript forum.



Done
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not exactly what you need, but should give you the basic idea:


Eric
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Originally posted by Rob Prime:
I suggest somebody move this to our JavaScript forum.



I do not think this is a JavaScript related question. I got the impression the original poster was talking about working with an XML DOM (not a JavaScript DOM) via Java and the org.w3c.dom.Document interface and API. Based on the subsequent posts, including those by the original poster, that seems to be the case.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I agree, Mark. But it looks like John is satisfied, at least he said "Thanks guys" which sounds like he's okay so far.
 
reply
    Bookmark Topic Watch Topic
  • New Topic