Note that you have two errors in your XML which prevent it from being parsed/well formed. After fixing those, the code appears to work when I tried it. That or I don't understand what you are trying to do. What behavior are you seeing that you don't expect.
On a side note, the whole task could be done in one line with a regular expression. (Or three lines if you count reading/writing the file)
The ?s is DOT_ALL which means to treat new lines as normal characters. The rest says to replace the two tags and everything in between with a blank space.
the whole task could be done in one line with a regular expression.
While that would work in this case, generally I advise against using regexps for XML processing. The format of XML can change in ways that leave XML parsing (and thus processing) unaffected, but which would break regexps. So I think it's better not to get into the habit even for tasks where it would work (unless you know up front that the format of the XML in question will not change).
I had not realised this had been commented on so are you saying Jeanne that I could use the line of code you mentioned rather than my nodelist thing?
Also what did you mean when you referred to xml errors? What outcome did you get from my code when you tried it?
For me it does appear to remove what I wanted but the file is abit messed up - everythings duplicated and the environments are all over the place and now because I have more code and it's different to how it was when I posted its throwing a null pointer exception but it has only done so since I re added the code from my post
*edit* in regards to the environment there are lots of different ones - I only want to delete the one which matches what the variable 'value' is holding - Thank you for your previous answers too
Alice: If your end DefEnv tag correct? What about the <Property> element inside the <DriverProperties> element?
Each element is made up of a start tag and and end tag, as in <mytag> </mytag>. If an element has no content, it can be abbreviated as <mytag/>
You said that you wanted to only remove those environment elements which have a particular value, but your sample code doesn't even refer to a value element?
The environment element is the element which starts with <Environment id="Test"> and ends with </Environment>. Is that what you're wanting to remove? Those two tags and all the content contained within them?
The Value element is actually quite deep within your sample XML: DefEnv/Environment/DB/DriverProperties/Value.
What exactly are you trying to remove and what basis do you want to use to locate the element to be removed?