[Home] [By Thread] [By Date] [Recent Entries]

  • To: xml-dev@l...
  • Subject: Re: adding new attribute to an existing xml file usingJAXP with DOM
  • From: Rahil <qamar_rahil@y...>
  • Date: Fri, 05 Aug 2005 16:50:44 +0100
  • Reply-to: qamar_rahil@y...
  • User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax)

Hi

When I wrote the line doc.appendChild(tagNode); after adding the 
attribute it generated the error:

----
org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to 
insert a node where it is not permitted.
   at org.apache.xerces.dom.CoreDocumentImpl.insertBefore(Unknown Source)
   at org.apache.xerces.dom.NodeImpl.appendChild(Unknown Source)
   at TestFile.addMIDs(TestFile.java:78)
   at TestFile.main(TestFile.java:115)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
----

Im obviously doing something wrong.

I used the logic that I first cast the Node to an Element and then 
access the Element methods to setAttribute(name,value). I then didnt 
know how to update the Element to the Document so simply appended it. I 
think Im doing something wrong here.

Thanks for helping out
Rahil





Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member