Results 1 to 1 of 1
  1. #1
    R O C K Y's Avatar
    R O C K Y is offline Member
    Join Date
    Feb 2009
    Posts
    19
    Rep Power
    0

    Question HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted

    Dear all members

    I am getting this error when i try to insert a new element(record) into my existing xml file.

    XML File:

    <Users>
    <User ID="1">
    <Username>N1</Username>
    <Role>R1</Role>
    </User>

    <User ID="2">
    <Username>N2</Username>
    <Role>R2</Role>
    </User>
    </Users>
    Java Code:
    Document xmlDomObject = parseXMLDocument();

    Node rootNode = xmlDomObject.getDocumentElement();

    Element userElement = xmlDomObject.createElementNS(null, "USER");
    userElement.setAttribute("ID",newUserRecordID);
    userElement.setAttribute("Name", userName);

    // Create Child element for User Name.
    Element userNameElement = xmlDomObject
    .createElementNS(null, "UserName");
    Node userNameElementNode = xmlDomObject.createTextNode(userName);
    userNameElement.appendChild(userNameElementNode);

    // Create Child element for User Name.
    Element roleElement = xmlDomObject.createElementNS(null, "Role");
    Node roleElementNode = xmlDomObject.createTextNode(Role);
    roleElement.appendChild(roleElementNode);

    userElement.appendChild(userNameElement);
    userElement.appendChild(roleElement);

    DocumentFragment documentFragment = xmlDomObject.createDocumentFragment();
    documentFragment.appendChild(userElement);

    rootNode.insertBefore(documentFragment,rootNode.ge tFirstChild().getNextSibling());//or use this -->rootNode.getChildNodes().item(1));

    xmlDomObject.appendChild(rootNode);//HERE I AM GETTING THE BELOW ERROR


    // Start Serialization Process using Serializable interface method - writeObject.
    serialize(xmlDomObject);
    Error:

    Users
    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.insertBefor e(Unknown Source)
    at org.apache.xerces.dom.NodeImpl.appendChild(Unknown Source)
    at com.javafiles.AddNewUserToXML.addNewUser(AddNewUse rToXML.java:76)
    at com.handler.NewUserHandler.doPost(NewUserHandler.j ava:215)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:710)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:174)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:874)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11 ConnectionHandler.processConnection(Http11BaseProt ocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Thread.java:619)
    I want to add new user each time when a new user registered with us using servlet.
    Through servlet i am trying to add new user profile in xml file located in user home at client side.


    Please help me out of this problem..........

    waiting for your reply.........:(
    Last edited by R O C K Y; 02-18-2009 at 07:41 AM.

Similar Threads

  1. XML Node.getNodeValue Problem
    By mindscape777 in forum XML
    Replies: 1
    Last Post: 01-11-2009, 03:22 PM
  2. Using for loops to create a "bridge" made out of hyphens
    By carlodelmundo in forum New To Java
    Replies: 7
    Last Post: 09-21-2008, 12:20 PM
  3. How to disabled a node.
    By smartsubroto in forum New To Java
    Replies: 32
    Last Post: 07-01-2008, 08:30 AM
  4. Node selection in jtree
    By Preethi in forum AWT / Swing
    Replies: 4
    Last Post: 06-20-2008, 12:25 AM
  5. Replies: 1
    Last Post: 07-14-2007, 06:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •