document.removeChild(node child)

Mark Cheek mcheek at NetVendor.com
Wed Aug 4 00:49:47 BST 1999


can anyone explain to me either:
	1::why my code throws an exception OR
	2::how to remove a node from a Document object
?
I have a Document object that was instantiated using a DOM
implementation while parsing an XML file.. whenever I try to remove one
of the leaves from the Document object, I always receive an exception
at: 
DOMExceptionImpl

thanks for your time,
-mark

---------CODE IS BELOW THIS LINE-----------
		public void deleteNode(MutableTreeNode node)
		{
			//delete node from model
			System.out.println(node.toString());
			removeNodeFromParent(node);
			fireTreeNodesRemoved(this,new
Object[]{getRoot()},new int[0], new Object[0]);

			Node aNode = this.getNode(node);
			System.out.println(aNode.toString());
			System.out.println(nodeMap.toString());

			//loop through document and match node??
			NodeList zList =
document.getElementsByTagName("item");
			for(int z=0;z<zList.getLength();z++)
			{

System.out.println(zList.item(z).getNodeName());

System.out.println(zList.item(z).getNodeType());

System.out.println(zList.item(z).getNodeValue());

				if(zList.item(z).hasChildNodes())
				{
					NodeList yList =
zList.item(z).getChildNodes();
					for(int y
=0;y<yList.getLength();y++)
					{

System.out.println(yList.item(y).getNodeName());	//=#text

System.out.println(yList.item(y).getNodeType());	//=3

System.out.println(yList.item(y).getNodeValue());	//here=OrderNo
						String value =
yList.item(y).getNodeValue();

if(value.equals(node.toString()))
						{
                            try
                            {
                                document.removeChild(yList.item(y));
//<=EXCEPTION THROWN HERE!
                            }
                            catch(Exception e)
                            {
                                e.printStackTrace();
                            }
						}
					}
				}
			}

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To (un)subscribe, mailto:majordomo at ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)





More information about the Xml-dev mailing list