This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Removing node/element from DOM

 
Ulrich Von Litchtenstein
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I came across this problem where I cant remove element from the document.

Here is my code.



Basically I am reading XML file of another website and putting it in a string and parsing it. Now to implement a search functionality, I need to get rid of an element.

I tried it the following way as suggest by a website while googling,



It removes stuff from the NodeList when I do a out.println() before and after this code to verify, but document remains intact when I print it out (using xsl to format it and Transformer). But thats what I expected anyway.

I simply dont know how to remove an element from the actual DOM document. Any ideas anyone?

Cheers for looking at it.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on JSP. For more information, please read this.

This post has been moved to a more appropriate forum.
 
Paul Clapham
Sheriff
Pie
Posts: 20176
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A little more detail would be helpful. From what you've posted it appears you are trying to delete the second "name" element from an XML document, but that's all I can tell. Sample input document? Source code? Resulting output?
 
Ulrich Von Litchtenstein
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Please take the time to choose the correct forum for your posts. This forum is for questions on JSP. For more information, please read this.

This post has been moved to a more appropriate forum.


Sorry, I am doing all this in a JSP page hence it was put here. Its one of those codes that you can put into normal java or JSP.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As such, it is not a JSP question. Thanks.
 
Ulrich Von Litchtenstein
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:A little more detail would be helpful. From what you've posted it appears you are trying to delete the second "name" element from an XML document, but that's all I can tell. Sample input document? Source code? Resulting output?


Hi Paul,

The XML file is massive, but its something like this



Basically I am trying to remove one of the name element.

If i do document.removeChild("name"); then the compiler wouldnt know which "name" I am trying remove. So I put it in a nodelist which will index all the names but that too didn't work.

 
Paul Clapham
Sheriff
Pie
Posts: 20176
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulrich Von Litchtenstein wrote:Sorry, I am doing all this in a JSP page hence it was put here. Its one of those codes that you can put into normal java or JSP.


Yes, well you might be better off to just write a plain old Java application to test your code. You're probably finding that a JSP is not a very good testing environment.
 
Paul Clapham
Sheriff
Pie
Posts: 20176
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulrich Von Litchtenstein wrote:
Basically I am trying to remove one of the name element.

If i do document.removeChild("name"); then the compiler wouldnt know which "name" I am trying remove. So I put it in a nodelist which will index all the names but that too didn't work.



If it didn't work, then you should try doing something differently.

You haven't said in what way it didn't work and you still haven't posted a piece of code that exhibits the problem. There's not much anybody can do until you come up with something specific. Preferably specific input, code which produces incorrect output, explanation of why it's incorrect. That shouldn't be hard as your requirement is quite simple.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic