Johannes,

I have faced similar issues in the past. I have got it to work but I
have to admit in the most inelegant way possible.
I get the xml from the node and reparse it using :-

    public synchronized org.w3c.dom.Document
reparseXmlBeansOutput(byte[] xml,
            boolean namespaceAware) {
        org.w3c.dom.Document retVal = null;
        DocumentBuilderFactory dbFactory =
DocumentBuilderFactory.newInstance();
        DocumentBuilder builder;
        try {
            dbFactory.setNamespaceAware(namespaceAware);
            builder = dbFactory.newDocumentBuilder();
            ByteArrayInputStream str = new ByteArrayInputStream(xml);
            retVal = builder.parse(str);
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return retVal;
    }


The byte[] is XmlObject.xmlText().getBytes();

Then I create an XmlObject from the DOM Node and add it to target tree.

There has to be a better solution and if someone has one I'd be glad to
hear.

Regards

Don

-----Original Message-----
From: Johannes Echterhoff [mailto:[EMAIL PROTECTED] 
Sent: 06 September 2005 18:23
To: [email protected]
Subject: Re: Child to add is from another document

This also did not work - maybe because i am not familiar enough with the
dom-api.

But: ... i accidentally stepped over the method: public XmlObject
set(XmlObject srcObj) in XmlObject and this here works (i am adding the
code so that maybe another one who has the same problem might solve it
with this):

...
public class XMLBeansANYTest {
 
    public static void main(String[] args) {
       
            AMTargetConfigurationDocument atcd =
AMTargetConfigurationDocument.Factory.newInstance();
            AMTargetConfiguration atc =
atcd.addNewAMTargetConfiguration();

                   
            AXISConnectorConfigDocument accd =
AXISConnectorConfigDocument.Factory.newInstance();
            AXISConnectorConfigType acct =
accd.addNewAXISConnectorConfig();
        
            atc.set(accd);
           
            System.out.println("Created following
AMTargetConfigurationDocument:");
            System.out.println(atcd.toString());
           
            System.out.println();
           
            Node configNode =
atcd.getAMTargetConfiguration().getDomNode();
           
            NodeList childList = configNode.getChildNodes();
            Node axisConnectorConfigNode = null;
           
            // Find the AXISConnectorConfig-element and make sure it's
            // <AXISConnectorConfig>.
            for (int i = 0; i < childList.getLength(); i++)
            {
                Node node = childList.item(i);
                if (node.getNodeType() == Node.ELEMENT_NODE)
                {
                    if
(node.getLocalName().equals("AXISConnectorConfig"))
                    {
                        axisConnectorConfigNode = node;               
                        break;
                    }
                }
            }
           
       
            AXISConnectorConfigDocument configDoc = null;
            try {
                configDoc =
AXISConnectorConfigDocument.Factory.parse(axisConnectorConfigNode);
            } catch (XmlException e) {
                System.out.println("Could not parse
AXISConnectorConfigDocument."+e.getMessage());
                e.printStackTrace();
            }
            System.out.println("Received following
AXISConnectorConfigDocument from created
AMTargetConfigurationDocument:");
            System.out.println(configDoc);
    }
}

Output is:
Created following AMTargetConfigurationDocument:
<AMTargetConfiguration xmlns="http://www.52north.org/sps"; 
xmlns:axis="http://www.52north.org/axis";>
  <axis:AXISConnectorConfig/>
</AMTargetConfiguration>

Received following AXISConnectorConfigDocument from created
AMTargetConfigurationDocument:
<AXISConnectorConfig xmlns="http://www.52north.org/axis"/>

Best regards and thanks for the replies,
    Johannes Echterhoff


Eric Vasilik wrote:

>You will need to import the node from one document to the other.  Use 
>"importNode" from the document interface.
>
>- Eric
>
>On 9/6/05, Johannes Echterhoff <[EMAIL PROTECTED]> wrote:
>  
>
>>Hi.
>>Cloning the node to insert did not work out. Still the same message. 
>>The program now looks like:
>>
>>public class XMLBeansANYTest {
>>
>>   public static void main(String[] args) {
>>
>>       AMTargetConfigurationDocument atcd = null;
>>       try {
>>           atcd = AMTargetConfigurationDocument.Factory.newInstance();
>>           AMTargetConfiguration atc =
atcd.addNewAMTargetConfiguration();
>>           Node configNode = atc.getDomNode();
>>
>>           AXISConnectorConfigDocument accd = 
>>AXISConnectorConfigDocument.Factory.newInstance();
>>           AXISConnectorConfigType acct = 
>>accd.addNewAXISConnectorConfig();
>>
>>           Node clonedNode = acct.getDomNode().cloneNode(true);
>>
>>           configNode.insertBefore(clonedNode,null);
>>
>>       } catch (Exception e) {
>>           e.printStackTrace();
>>       }
>>       System.out.println(atcd.toString());
>>   }
>>}
>>
>>Any other suggestions?
>>
>>Regards,
>>   Johannes Echterhoff
>>
>>
>>Don Stewart wrote:
>>
>>    
>>
>>>Johannes,
>>>
>>>Not 100% sure but your adding an element from one doc to another and 
>>>so you (maybe) need to use clone() on the DOM node and add the cloned

>>>node to your other document.
>>>
>>>Regards
>>>
>>>Don
>>>
>>>-----Original Message-----
>>>From: Johannes Echterhoff [mailto:[EMAIL PROTECTED]
>>>Sent: 06 September 2005 12:45
>>>To: [email protected]
>>>Subject: Child to add is from another document
>>>
>>>Hi.
>>>I just tried to put the contents of one document into the any-element

>>>of another document. I got following error:
>>>
>>>org.apache.xmlbeans.impl.store.DomImpl$WrongDocumentErr: Child to add

>>>is
>>>      
>>>
>>>from another document
>>    
>>
>>>   at
>>>org.apache.xmlbeans.impl.store.DomImpl._node_insertBefore(DomImpl.jav
>>>a:1
>>>756)
>>>   at
>>>org.apache.xmlbeans.impl.store.Xobj$NodeXobj.insertBefore(Xobj.java:2
>>>459
>>>)
>>>   at test.XMLBeansANYTest.main(XMLBeansANYTest.java:56)
>>>
>>>
>>>The programs main-code looks like this:
>>>
>>>       AMTargetConfigurationDocument atcd = null;
>>>       try {
>>>           atcd =
AMTargetConfigurationDocument.Factory.newInstance();
>>>           AMTargetConfiguration atc = 
>>>atcd.addNewAMTargetConfiguration();
>>>           Node configNode = atc.getDomNode();
>>>
>>>           AXISConnectorConfigDocument accd = 
>>>AXISConnectorConfigDocument.Factory.newInstance();
>>>           AXISConnectorConfigType acct = 
>>>accd.addNewAXISConnectorConfig();
>>>
>>>           configNode.insertBefore(acct.getDomNode(),null);
>>>
>>>       } catch (Exception e) {
>>>           e.printStackTrace();
>>>       }
>>>       System.out.println(atcd.toString());
>>>
>>>
>>>
>>>The schema for AMTargetConfiguration looks like this:
>>>
>>><xs:element name="AMTargetConfiguration">
>>>       <xs:complexType>
>>>           <xs:sequence>
>>>               <xs:any processContents="skip"/>
>>>           </xs:sequence>
>>>       </xs:complexType>
>>>   </xs:element>
>>>
>>>
>>>I had a look at docs/guide/conHandlingAny.html but still do not get 
>>>the clue. Can someone please tell me what this error means and how to

>>>solve it?
>>>
>>>Regards,
>>>   Johannes Echterhoff
>>>
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>>
>>>
>>>
>>>      
>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to