I have two Nodes node1 and nod2 which have different parent documents, now I want to call
node1.appendChild(node2);
function for this nodes but my application crashes, below you can see owner documents and XMLs of nodes.
Document document1 = node1.getOwnerDocument();
Document document2 = node2.getOwnerDocument();
Both nodes have different owner documents. node1 owner document described below
<?xml version="1.0" encoding="UTF-8"?>
<ClientGetOTPSeedMessage>
<UserID>userID</UserID>
<DeviceInfo/>
</ClientGetOTPSeedMessage>
and node2 owner document is as follow:
<?xml version="1.0" encoding="UTF-8"?>
<Desc>
<Desc1>First name</Desc1>
<Desc2>Second name</Desc2>
</Desc>
Now I want to get </Desc> node from document2 and put it to <DeviceInfo/> node in the document1 how I can do it. And I want to say that node1 and node2 keep the nodes which I want to add one to another, but when I write
node1.appendChild(node2);
my application crashes, I guess the main reason is that they have different owner documents.
The reason the application crashes is, as you said,the different owner documents (see this for more details). To solve the problem you should import node2 in document1, like this:
and then:
More info about import here.