• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dom and empty nodes

 
John Landon
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Clapham
Sheriff
Pie
Posts: 20729
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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: 228
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Pie
Posts: 20729
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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?
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • 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 ]
 
Rob Spoor
Sheriff
Pie
Posts: 20493
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest somebody move this to our JavaScript forum.
 
John Landon
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys.
 
Campbell Ritchie
Sheriff
Posts: 48381
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:
I suggest somebody move this to our JavaScript forum.


Done
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Pie
Posts: 20729
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic