You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Peter Vanopulos <pe...@pivod.com> on 2003/04/03 04:39:54 UTC
removeChild problem
Hi All,
I am using Xerces-J version 2.2.1 and having a weird issue with the
removeChild() method:
Document doc = ..... populated with xml...
First I start by printing out the contents of the "Document doc"...
try {
OutputFormat format = new OutputFormat( doc );
//Serialize DOM
StringWriter stringOut = new StringWriter();
//Writer will be a String
XMLSerializer serial = new XMLSerializer( stringOut,
format );
serial.asDOMSerializer(); // As a
DOM Serializer
serial.serialize( doc.getDocumentElement() );
System.out.println( stringOut.toString() );
} catch ( Exception ex ) {
ex.printStackTrace();
}
Now I try and delete a specific node....
NodeList nl = doc.getElementsByTagName("service");
for ( int i=0; i<nl.getLength(); i++ ) { //goes through all the service
nodes
Node e2 = nl.item(i);
Element e = (Element)nl.item(i);
NamedNodeMap nnm = e.getAttributes();
for ( int j=0; j<nnm.getLength(); j++ ) {
//goes through service nodes attributes
if (
nnm.item(j).getNodeName().equals("name") &&
nnm.item(j).getNodeValue().equals(serviceName)) {
try {
Node
deletedNode = e2.getParentNode().removeChild( e2 );
If I try and look at the "Document doc", my deleted node is still there?
try {
OutputFormat format = new OutputFormat( doc );
//Serialize DOM
StringWriter stringOut = new StringWriter();
//Writer will be a String
XMLSerializer serial = new XMLSerializer( stringOut,
format );
serial.asDOMSerializer(); // As a
DOM Serializer
serial.serialize( doc.getDocumentElement() );
System.out.println( stringOut.toString() );
} catch ( Exception ex ) {
ex.printStackTrace();
}
Is this a bug with the version I am using?
Am I doing something incorrectly?
Suggests much appreciated.
Thanks,
Peter Vanopulos * Programmer * PIVoD Technologies
Perth Office (Head Office)
Phone +61 8 9284 8666 Fax +61 8 9284 8667
1st Floor 47-49 Stirling Hwy
Nedlands, Western Australia 6009
International Sales Office
Phone +61 3 8341 7218 Fax +61 8 9284 8667
Level 50, 101 Collins St
Melbourne, Victoria 3000
AUSTRALIA
Sydney Sales Office
Phone +61 2 9411 4148 Fax +61 9411 8742
315 Mowbray Road
Chatswood, Sydney NSW 2067
AUSTRALIA
Benelux Sales Office (PIVoD BV)
Phone +31 020 888 4560 Fax +31 020 888 4561
Kruislaan 419, 1098 VA
Amsterdam, The Netherlands
www.pivod.com <http://www.pivod.com/>
*************************************************
This email and any files transmitted with it are confidential and
intended for use by the Addressee only. The confidential nature
of the information contained in the email and/or file is not waived,
lost or destroyed if it is sent in error to other than the Addressee.
Use or dissemination of the information contained in the email
and/or files by a recipient other than the Addressee may cause
commercial damage to both/either the Sender and/or Addressee.
If you are not the Addressee of this email/files please immediately
contact the Sender and delete this email/files.
**************************************************