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
    Rep Power

    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:

    <User ID="1">

    <User ID="2">
    Java Code:
    Document xmlDomObject = parseXMLDocument();

    Node rootNode = xmlDomObject.getDocumentElement();

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

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

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


    DocumentFragment documentFragment = xmlDomObject.createDocumentFragment();

    rootNode.insertBefore(documentFragment, 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.

    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
    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 ternalDoFilter(
    at Filter(
    at org.apache.catalina.core.StandardWrapperValve.invo ke(
    at org.apache.catalina.core.StandardContextValve.invo ke(
    at org.apache.catalina.core.StandardHostValve.invoke(
    at org.apache.catalina.valves.ErrorReportValve.invoke (
    at org.apache.catalina.core.StandardEngineValve.invok e(
    at org.apache.catalina.connector.CoyoteAdapter.servic e(
    at org.apache.coyote.http11.Http11Processor.process(H
    at org.apache.coyote.http11.Http11BaseProtocol$Http11 ConnectionHandler.processConnection(Http11BaseProt
    at Socket(
    at ead.runIt(
    at org.apache.tomcat.util.threads.ThreadPool$ControlR
    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, 11:20 AM
  3. How to disabled a node.
    By smartsubroto in forum New To Java
    Replies: 32
    Last Post: 07-01-2008, 07:30 AM
  4. Node selection in jtree
    By Preethi in forum AWT / Swing
    Replies: 4
    Last Post: 06-19-2008, 11:25 PM
  5. Replies: 1
    Last Post: 07-14-2007, 05: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