DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5095>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5095

getElementsByTagName doesn't return siblings properly





------- Additional Comments From [EMAIL PROTECTED]  2001-11-26 13:18 -------
Here is a code snippet:

import java.io.File;
import java.io.IOException;

import java.util.HashMap;
import java.util.Vector;
import java.util.Set;
import java.util.Iterator;

import javax.xml.parsers.DocumentBuilder; 
import javax.xml.parsers.DocumentBuilderFactory;  
import javax.xml.parsers.FactoryConfigurationError;  
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;  
import org.xml.sax.SAXParseException;

public class TestXml
{
   public static void main(String[] argv)
   {
      try
      {
         File templateFile = new File(argv[0]);
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         DocumentBuilder builder = factory.newDocumentBuilder();
         Document document = builder.parse(templateFile);

         NodeList nodes = document.getElementsByTagName(argv[1]);
         for (int i = 0; i < nodes.getLength(); i ++)
         {
            Node elementToReplace = nodes.item(i);

            NamedNodeMap nodeMap = elementToReplace.getAttributes();
            Node nameNode = nodeMap.getNamedItem("name");

            String elementName = nameNode.getNodeValue();
            System.out.println("Found: " + elementName);

            Node parentNode = elementToReplace.getParentNode();

            // we no longer need this
            parentNode.removeChild(elementToReplace);
         }

         System.out.println("Done");
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
   }
}

If I don't remove the node I explored, the code works fine. I think that is the 
problem. (But for my program, I need to remove the node.)

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to