aspose file tools*
The moose likes Servlets and the fly likes Exception while replacing an XML tag in an XML file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Exception while replacing an XML tag in an XML file" Watch "Exception while replacing an XML tag in an XML file" New topic
Author

Exception while replacing an XML tag in an XML file

Devarakonda Srikanth
Greenhorn

Joined: Aug 27, 2007
Posts: 25
Hi,

When I am trying to replace the existing XML tag with other one I am getting the following exception:

org.w3c.dom.DOMException: NOT_FOUND_ERR: An attempt is made to reference a node in a context where it does not exist.
at org.apache.xerces.dom.ParentNode.internalInsertBefore(Unknown Source)
at org.apache.xerces.dom.ParentNode.replaceChild(Unknown Source)
at org.apache.xerces.dom.CoreDocumentImpl.replaceChild(Unknown Source)
at com.Replace_Tag.replaceNode(Replace_Tag.java:97)
at com.Replace_Tag.processRequest(Replace_Tag.java:39)
at com.Replace_Tag.doGet(Replace_Tag.java:56)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)

The following is the code I am using :


code:
--------------------------------------------------------------------------------

public void replaceNode() throws Exception{ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse("file:/C:/Documents and Settings/srikanth.d.KNOAHSOFT/Desktop/Linechart.jrxml"); Element root = doc.getDocumentElement(); Element newElement = doc.createElement("stackedBarchart"); NodeList oldList = root.getElementsByTagName("lineChart"); int length = oldList.getLength(); System.out.println("length::"+length); for(int i=0;i<length;i++) { Node oldNode = oldList.item(i); NodeList nl = doc.getChildNodes(); newElement.getTagName().toString()); (i).getNodeName().toString()); doc.replaceChild((Node)newElement, oldNode); } }

--------------------------------------------------------------------------------





Can anybody help me in this regard...

Thanks and Regards
DNV Srikanth
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

This seems to be more XML related than Servlet related.
Moving to our XML forum.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
Don't get me started about those stupid light bulbs.
 
subject: Exception while replacing an XML tag in an XML file