0

How can I remove all the nodes between two comment nodes using java DOM apis. I have below xml format.

.
.
<!-- start: my configs --> 

<student id="100">
    <school>Saint Dnyaneshwar School</school>
    <division>science</division>
    <percentage>60.06</percentage>
</student>

<student id="101">
    <school>Saint Dnyaneshwar School</school>
    <division>Marathi</division>
    <percentage>77.06</percentage>
</student>

<!-- end: my configs --> 
.
.
.

I want to remove all the nodes between start: my configs and end: my configs comments nodes. How this can be achieved uding Java DOM apis.

Thanks in advance.

Aryan
  • 1,767
  • 2
  • 22
  • 39
  • 1
    I don't believe you can, comments are exactly that a non functional requirement. Rather add a tag Like and build system logic around that , if you find a valid MyConfig use that config. else you will have to use sting manipulation find the first instance of – Kenneth Clark May 08 '14 at 06:15
  • The reason to have comments instead of any tag is that I dont really control the XML file. I have an entity which puts some configs in this file. There are lot of other entities which does the same. So only option is to highlight is the comments. I am not allowed to have my own tags, basically that will break the XML. – Aryan May 08 '14 at 06:18
  • I think you are stuck a bit , personally id ask why you have the tags there if you are not meant to add them. But here is an example to read a comment, parse the xml find the comment node and remove the next node. http://stackoverflow.com/questions/15245860/java-reading-comment-from-xml-file – Kenneth Clark May 08 '14 at 10:01

0 Answers0