Org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR

Hi All,
I am getting following exception at the time of XML making by Java.
org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.
at org.apache.xerces.dom.ParentNode.internalInsertBefore(Unknown Source)
at org.apache.xerces.dom.ParentNode.insertBefore(Unknown Source)
at org.apache.xerces.dom.NodeImpl.appendChild(Unknown Source)
Thanks,
Vishal

This code is reading data from the database and converts it to a XML document by using DOM and then saves it to a .xml file.
It compiles without any error but when I try to run it, then I get the error given in my earlier post. I hope this explains what the code is suppose to do.

Similar Messages

  • Exception in thread "main" org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR:

    Hi All,
    i craeted a array of Document...
    I used it as ....
    while(DivideRows>0)
    dom[Domcnt]= initiatexml.createDocument(dom);
    DivideRows = DivideRows - 5;
    Domcnt++;
    ......On this i dont get any error
    But for this snippet i get an error
    String[] packageBody = {"A","B","C"};
    rootEle = dom[Domcnt].createElement(packageBody[Domcnt]);
    rootEle.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
    rootEle.setAttribute("xmlns", "http://www.vignette.com/xmlschemas/importexport");
    rootEle.setAttribute("xsi:schemaLocation", "http://www.vignette.com/xmlschemas/importexport 7310/packageBody.xsd");
    dom[Domcnt].appendChild(rootEle); //////////error//////
    return rootEle;
    the error is
    Exception in thread "main" org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted.

    No: http://www.w3.org/TR/REC-xml/#sec-well-formed

  • Org.w3c.dom.DOMException: NO_MODIFICATION_ALLOWED_ERR

    Hi,
    I got this error when trying to add new node to Document object
         public Document createDomFromXML(String strXmlFile)
              throws Exception {
              DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();     
              Document document = builder.parse(strXmlFile);
              return document;
                         dom=createDomFromXML("tempa\late.xml");
                         dom.getFirstChild().appendChild(entityNode);
                         //got error here
    my xml file is
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE tree [ 
    <!ELEMENT tree (entity*)>
    <!ELEMENT entity (description*,image*,imageOpen*,contents*)>
    <!ELEMENT description (#PCDATA)>
    <!ELEMENT image (#PCDATA)>
    <!ELEMENT imageOpen (#PCDATA)>
    <!ELEMENT contents (#PCDATA)>
    <!ATTLIST tree idCount CDATA #IMPLIED>
    <!ATTLIST entity id ID #REQUIRED>
    <!ATTLIST entity modify CDATA #IMPLIED>
    <!ATTLIST entity parentid CDATA #IMPLIED>
    <!ATTLIST entity hours CDATA #IMPLIED>
    <!ATTLIST entity minutes CDATA #IMPLIED>
    ]>
    <tree xml:IdCount="0"></tree>
    Please help
    Regards
    Siddharth

    In the [DOM specification|http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407] a Document can only have one Element child. This is the 'document element'. You should be appending to that, not the Document.

  • Org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML

    hi to all ,
    i am trying to convert excel (*.xls ) file to xml file in my j2ee application ,
    while i am trying this i am getting an Exception that INVALID_CHARACTER_ERR .But i am unable to find where i did mistake.
    i am using java 1.6.0, linux, jboss application server4.2.3GA,
    and i have added poi3.6.jar file and dom3-core-tests-20040405.jar files into my application .
    when i invoke a method , i am getting this exception in my server console,
    here is my method,
         public void generateXML() {
         try { //Initializing the XML document
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         DocumentBuilder builder = factory.newDocumentBuilder();
         Document document = builder.newDocument();
         Element rootElement = document.createElement("booking-file");
         document.appendChild(rootElement);
         Element stmtElement1 = document.createElement("booking");
         rootElement.appendChild(stmtElement1);
         Element stmtElement2 = document.createElement("booking");
         rootElement.appendChild(stmtElement2);
         InputStream input = new FileInputStream("/home/logic/Desktop/BOOKING.xls");
         HSSFWorkbook workbook = new HSSFWorkbook(input);
         HSSFSheet spreadsheet = workbook.getSheetAt(0);
         for (int i = 1; i <= spreadsheet.getLastRowNum(); i++) {
         switch (i) {
              case 1:
         HSSFRow row1 = spreadsheet.getRow(1);
         Element revenueElement1 = document.createElement("VoyageNumber");
         stmtElement1.appendChild(revenueElement1);
         revenueElement1.appendChild(document.createTextNode(row1.getCell((short) 1).getStringCellValue()));
         Element revenueElement2 = document.createElement("VoyageNumber");
         stmtElement2.appendChild(revenueElement2);
         revenueElement2.appendChild(document.createTextNode(row1.getCell((short) 2).getStringCellValue()));
         break;
         case 2:
         HSSFRow row2 = spreadsheet.getRow(2);
         Element costofrevenue1 = document.createElement("Vessel/IMOCode");
         stmtElement1.appendChild(costofrevenue1);
         costofrevenue1.appendChild(document.createTextNode(row2.getCell((short)1).getStringCellValue()));
         Element costofrevenue2 = document.createElement("Vessel/IMOCode");
         stmtElement2.appendChild(costofrevenue2);
         costofrevenue2.appendChild(document.createTextNode(row2.getCell((short) 2). getStringCellValue()));
         break;
         case 3:
         HSSFRow row3 = spreadsheet.getRow(3);
         Element researchdevelopment1 = document.createElement("VesselName");
         stmtElement1.appendChild(researchdevelopment1);
         researchdevelopment1.appendChild(document.createTextNode(row3.getCell((short) 1).getStringCellValue()));
         Element researchdevelopment2 =document.createElement("VesselName");
         stmtElement2.appendChild(researchdevelopment2);
         researchdevelopment2.appendChild(document.createTextNode(row3.getCell((short) 2).getStringCellValue()));
         break;
         case 4:
         HSSFRow row4 = spreadsheet.getRow(4);
         Element salesmarketing1 = document.createElement("Carrier");
         stmtElement1.appendChild(salesmarketing1);
         salesmarketing1.appendChild(document.createTextNode(row4.getCell((short) 1).getStringCellValue()));
         Element salesmarketing2 = document.createElement("Carrier");
         stmtElement2.appendChild(salesmarketing2);
         salesmarketing2.appendChild(document.createTextNode(row4.getCell((short) 2).getStringCellValue()));
         break;
         case 5:
         HSSFRow row5 = spreadsheet.getRow(5);
         Element generaladmin1 = document.createElement("BookingNumber");
         stmtElement1.appendChild(generaladmin1);
         generaladmin1.appendChild(document.createTextNode(row5.getCell((short) 1).getStringCellValue()));
         Element generaladmin2 = document.createElement("BookingNumber");
         stmtElement2.appendChild(generaladmin2);
         generaladmin2.appendChild(document.createTextNode(row5.getCell((short) 2).getStringCellValue()));
         break;
         default:
         break;
         TransformerFactory tFactory = TransformerFactory.newInstance();
         Transformer transformer = tFactory.newTransformer();
         transformer.setOutputProperty
         (OutputKeys.INDENT, "yes");
         transformer.setOutputProperty( "{http://xml.apache.org/xslt}indent-amount", "2");
         DOMSource source = new DOMSource(document);
         StreamResult result = new StreamResult(System.out);
         transformer.transform(source, result);
         } catch (IOException e) {  System.out.println("IOException " + e.getMessage());
         } catch (ParserConfigurationException e) {
         System.out
         .println("ParserConfigurationException " + e.getMessage());
         } catch (TransformerConfigurationException e) {
         System.out.println("TransformerConfigurationException "+ e.getMessage());
         } catch (TransformerException e) {
         System.out.println("TransformerException " + e.getMessage());
    can anyone please help me?
    Thanks for your help in advance
    Sathish A

    Please use the 'code' button when posting code. There are a number of things you can do. Call DocumentBuilder#setErrorHandler() and use org.xml.sax.helpers.DefaultHandler. That should give you a line number where things are broken. Or, easier, save the file you generate and try to open it in IE or Firefox. It will point out where the XML is not well formed.
    - Saish

  • Invoking BPEL process from Java servlet with org.w3c.dom.Element as payload

    Hello,
    I'm trying to initiate a BPEL process from my servlet running under Tomcat. When I create the NormalizedMessage passing the XML as a String everything works fine. But if I use an org.w3c.domElement the BPEL server doesn't react at all (even on DEBUG log level there are no outputs).
    This works:
    NormalizedMessage message = new NormalizedMessage();
    message.addPart("payload", "<foo></foo>");
    This doesn't work:
    org.w3c.dom.Element elem;
    oracle.xml.parser.v2.XMLDocument xmlDocument;
    NormalizedMessage message = new NormalizedMessage();
    Element elem = xmlDocument.createElement("foo");
    message.addPart("payload", elem);
    Is there a known problem with payloads using Element or did I get something completely wrong? Thanks in advance,
    Hans.

    Hello,
    I'm trying to initiate a BPEL process from my servlet running under Tomcat. When I create the NormalizedMessage passing the XML as a String everything works fine. But if I use an org.w3c.domElement the BPEL server doesn't react at all (even on DEBUG log level there are no outputs).
    This works:
    NormalizedMessage message = new NormalizedMessage();
    message.addPart("payload", "<foo></foo>");
    This doesn't work:
    org.w3c.dom.Element elem;
    oracle.xml.parser.v2.XMLDocument xmlDocument;
    NormalizedMessage message = new NormalizedMessage();
    Element elem = xmlDocument.createElement("foo");
    message.addPart("payload", elem);
    Is there a known problem with payloads using Element or did I get something completely wrong? Thanks in advance,
    Hans.

  • Finding import org.w3c.dom.ls.DOMOutput in rt.jar

    I'm taking over some code which uses
    import org.apache.xerces.dom.DOMOutputImpl;
    import org.apache.xerces.parsers.DOMParser;
    import org.apache.xml.serialize.DOMSerializerImpl;
    import org.w3c.dom.ls.DOMOutput;
    DOMOutput dOut = new DOMOutputImpl();
    private DOMSerializerImpl writer = new DOMSerializerImpl();That interace doesnt' appear to exist in 1.5.0_02, nor in 1.4.2_03. Does anyone know which version of the JDK/JRE included this?
    Thanks,
    Jeff

    I did a search on Sun site, nothing came back.
    It is on http://xml.apache.org/xerces2-j though.
    You might need to go there and download it. or make sure your
    classpath includes the right jar file.

  • Document in org.w3c.dom.*??

    Is Document in org.w3c.dom.* a file?what is its extension?
    How can i write a file with it?

    org.w3c.dom.Document is a class that represents an XML document.
    It does not represent an XML stream as mlk says.
    It doesn't have anything to do with files. You can use an XML parser to build up a Document in memory from an XML file or any other data source that produces XML. Class org.w3c.dom.Document does not have any methods by itself that you can use to write to an XML file.
    XML files usually have the extension ".xml", but they can also have other extensions.
    See this: Working with XML: The Java/XML Tutorial

  • Org.w3c.dom.Document to/from String ?

    I need to be able to parse (once) an XML string, and then pass the parsed object around to/from different objects.
    I tried to use org.w3c.dom.Document,
    generated by javax.xml.parsers.DocumentBuilder .
    HOWEVER - I don't see any way to parse an xml String!
    The doc-builder parse() method accepts either a file/url, or an InputStream.
    When I tried to use the StringBufferInputStream I found-out it is deprecated, and that I should use StringReader.
    BUT I cannot parse using StringReader ! (the method parse() doesn't work with it)
    Is there anyway to parse a String to create a Document ?
    ========================================================
    And that's only HALF my problem:
    I did parse an input file into a Document, to experiment a little.
    I then wanted to convert it to an XML String - but couldn't.
    How do I get the xml String from a Document ?
    I cannot: How do I save it to a file ?
    I must say that under .NET both tasks are TRIVIAL:
    XmlDocument.LoadXML()
    XmlDocument.OuterXml
    Thanks
    Meir

    The doc-builder parse() method accepts either a file/url, or an InputStream.This isn't true. Look it up again. There are overridden versions of parse() that use File, InputSource, InputStream, or String. The String one isn't what you want, because the String it takes is a URL pointing to the XML and not the XML itself. The File one doesn't work for you because you don't have a file, and you've already said why the InputStream one doesn't work for you.
    So that leaves the version that takes an InputSource. So, what is an InputSource anyway? You could look it up just by clicking on the link in the API docs...

  • Java.lang.ClassCastException: oracle.xml.parser.v2.XMLText cannot be cast to org.w3c.dom.Element

    Hello
    I am getting java.lang.ClassCastException: oracle.xml.parser.v2.XMLText cannot be cast to org.w3c.dom.Element error. This code is in java which is present in java embedding.
    The SOA is parsing the xml in java code using oracle.xml.parser.v2 . This wont be a problem if the SOA uses default w3c DOM parser. How do i force SOA to use w3c DOM parser.
    Is there any thing i can do with class loading?
    Kindly help.
    Regards
    Sharat

    Can you paste your java code here ? I assume, you must have tried type-casting.

  • Set Name of org.w3c.dom.Node (= chang the TagNam)

    Hi all,
    How I can set name of my object org.w3c.dom.Node.
    In fact, this is an Element and I want to chang the tag <label> to <LABEL> befort write out DOM to XML File
    thanks a lot
    dseaa

    org.w3c.dom.Element interface does not have a setTagName() method.
    Implement interface org/w3c/dom/contentModel/CMElementDeclaration which has a setTagName() method.
    http://www.w3.org/TR/2001/WD-DOM-Level-3-CMLS-20010419/java-binding.html

  • Problem of using "org.w3c.dom.Node" class

    I try to use removeChild(child) method of "org.w3c.dom.Node" object. it don't work.
    is it better to do child=null;

    child=null does nothing to the dom object
    removeChild works fine. You're just confused.
    You would need more info to have any chance of fixing the problem.

  • Cost of creating org.w3c.dom.Node

    I am trying to create an xml of cached data at run time. I need to know if this would increase the response time considerably ..?
    Is there any documents which talk about the cost of creating nodes(e.g.within loops) ..?
    public Node createnode(Document d, String node_name, int node_value) {
    org.w3c.dom.Node temp_element_node, temp_text_node;
    temp_element_node = d.createElement(node_name);
    temp_text_node = d.createTextNode(node_name);
    temp_text_node.setNodeValue(node_value + "");
    temp_element_node.appendChild(temp_text_node);
    return temp_element_node;
    Has anybody implimented a pool of nodes(like pool of database connections). Any information is appreciated!

    It would certainly depend somewhat on which parser you were using, but i can't imagine it would be any more costly than any other type of object.

  • NoSuchMethodError with org.w3c.dom.Node.getTextNode()

    Hi,
    I got a trouble with this method. I developped my app with Eclipse and jdk 1.5.
    I used the endrosed mechanism for updating xalan and xerces in my jre.
    Everything works fine on my computer, but as I want to run my app on an other machine, I got this error.
    I put a copy of my jre on the other machine and I launch the app from this jre. It seems the endorsed jars are taken in account, but it still doesn't work.
    Thanks for your help.

    I found ths solution.
    In my jre was missing the endorsed Dom.jar, found at jaxp.dev.java.net. to overwrite org.w3c.dom standard classes.

  • Adding org.w3c.dom.Node

    Hi,
    can someone please tell me if it is posible do read a org.w3c.dom.Node from one XML file, and than add it to another? Or is there a way to copy one org.w3c.dom.Node to another XML?
    Thanx,
    Alan.

    Refer to
    http://javaalmanac.com/egs/org.w3c.dom/CloneSubtree2.html

  • How to initialize a org.w3c.dom.Node object?

    Hello,
    I want to initialize an org.w3c.dom.Node object with an empty Node.
    How could I do that?
    Thanks
    Sylvain

    I want to create a Document.
    If I test your line, this error appears:
    "Default constructor cannot handle exception type javax.xml.parsers.ParserConfigurationException thrown by implicit super constructor. Must define an explicit constructor."
    Do you know what's happen?
    Thanks
    Sylvain

Maybe you are looking for

  • IChart Pie Chart doesn't response to SelectionEvent

    Hi, I have a pie chart. I would like to have the slices in the pie chart clickable. When one slice is selected, I would like to display the detail information in another iGrid table. I have done it with iChart Bar with no problem. However, it seems l

  • Required to show predefined folder structure inside doccument library

    Hi,  I am looking for out of box solution to add predefined folder structure ( folders inside folder) in document library. Folder1       --subfolder1       --subfolder2 Folder2 Can this be possible via custom content type? If not then can we do this

  • MAC leopard:  JFileChooser not using FileFiler correctly!?

    Hi guys, I am using FileFilter to filter files with extension ".fpp" in my JFileChooser.This works well in Windows.But in MAC , it shows the "application" files. I mean there are some files with ".app" extension and they are shown in JFileChooser.So

  • HR TEM : Posting

    Dear all, we are implementing Training Event Management without LSO. 1. In Business Event Data especially for External training, is it possible to connect the organizer data with Vendor master from FI side using the standard config (not customize). T

  • How Can I Turn Off Document Template

    I need to remove the option of opening a new template when clicking on 'New' in a document library. I don't want to delete the content type itself, just remove it as an option. When I click 'New' I want the option of opening a clean Excel, Word, Powe