aspose file tools*
The moose likes XML and Related Technologies and the fly likes Removing node/element from DOM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Removing node/element from DOM" Watch "Removing node/element from DOM" New topic
Author

Removing node/element from DOM

Ulrich Von Litchtenstein
Greenhorn

Joined: Oct 11, 2009
Posts: 8
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

Joined: Jan 10, 2002
Posts: 60053
    
  65

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.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

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

Joined: Oct 11, 2009
Posts: 8
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

Joined: Jan 10, 2002
Posts: 60053
    
  65

As such, it is not a JSP question. Thanks.
Ulrich Von Litchtenstein
Greenhorn

Joined: Oct 11, 2009
Posts: 8
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
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

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
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Removing node/element from DOM
 
Similar Threads
Need help in replacing a node value
Problem with dom4j "Getting started" example
Efficient XML Parsing
How to get nested elements using DOM
xml and java