You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by "Gupta, Vikas" <Vi...@commerceone.com> on 2002/12/10 22:52:07 UTC

Error in method appendChild() on the Document

Hi:

I have a sample WSDL document. This document has the schema embedded within
it (in node types). I need to create a Document whose contents are the
schema.
I try to use xpath expression to extract the node and then create an empty
document object. To the empty document object I add the node that I found
via xpath. On this method call, I get an error saying....

org.w3c.dom.DOMException: DOM005 Wrong document
        at
org.apache.xerces.dom.ParentNode.internalInsertBefore(ParentNode.java
:394)
        at
org.apache.xerces.dom.ParentNode.insertBefore(ParentNode.java:326)
        at
org.apache.xerces.dom.CoreDocumentImpl.insertBefore(CoreDocumentImpl.
java:386)
        at org.apache.xerces.dom.NodeImpl.appendChild(NodeImpl.java:224)



This is my sample document....

  <?xml version="1.0" encoding="utf-8" ?> 
 <definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:s0="http://sjmillerconsultants.com/webservices"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
targetNamespace="http://sjmillerconsultants.com/webservices"
xmlns="http://schemas.xmlsoap.org/wsdl/">
 <types>
  <s:schema elementFormDefault="qualified"
targetNamespace="http://yyy.com/webservices">
  <s:element name="Send">
  <s:complexType>
  <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="sXML" type="s:string" /> 
  </s:sequence>
  </s:complexType>
  </s:element>
 </types>
</definitions>

This is my sample program.

            Document document1 = parser.parse(uri);
            NodeList nl = XPathAPI.selectNodeList(document1,
"/definitions/types", document1);
            Node selNode = nl.item(0);

            DocumentBuilderFactory tmpFactory = null;
            DocumentBuilder tmpBuilder = null;
            tmpFactory = DocumentBuilderFactory.newInstance();
            tmpBuilder = tmpFactory.newDocumentBuilder();

            Document tmpinstanceDoc = tmpBuilder.newDocument(); // create a
new instance
 
            tmpinstanceDoc.appendChild(selNode); //============>>>>> Error
occurs on this one....



Any help will be appreciated.
Thanks.

Vikas

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Error in method appendChild() on the Document

Posted by Joseph Kesselman <ke...@us.ibm.com>.
A document can have only one Element child, and older versions of the DOM 
may not permit you to append an Element to a Document -- you were supposed 
to create the element as a side effect of the 
DOMImplemention.createDocument call. There are good reasons for this, 
having to do with the fact that some DOM factories may want to create 
different DOM implementation classes depending on doctype and root-element 
information.

DOM Level 3 was considering relaxing that restriction, allowing the root 
element to be removed and a new one attached, partly so folks would write 
things like DocumentBuilderFactory without having to violate the DOM 
spec... but I don't know whether that's still in the DOM3 working draft 
and/or whether Xerces has prototyped that behavior yet.

______________________________________
Joe Kesselman  / IBM Research


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org