K
kapiladhanvi
Hi Everyone,
I need to move nodes in a XML document ( doc1 ) in namespace A to
another XML document (doc2) in namespace B.
I have tried adoptNode() as shown below but the nodes in doc2 still
have namespace URI for the nodes as namespace A. Below is the code
( this is just to provide a gist of what I am doing, not exactly
compilable code here ) -
function Document swapNodesAndReturnNewDoc( String namespaceB,
Document doc1 )
{
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc2 = db.newDocument();
doc2.setDocumentURI( namespaceB );
Element root = doc1.getDocumentElement();
Node clonedNode = root.cloneNode(true);
doc2.adoptNode( clonedNode );
doc2.appendChild( clonedNode );
return doc2;
}
I have tried searching google and couldn't help around this. I have
tried importNode() too earlier and had the same results.. I would be
really glad to get any pointers as to where I might be going wrong.
Thanks
Dhanvi
I need to move nodes in a XML document ( doc1 ) in namespace A to
another XML document (doc2) in namespace B.
I have tried adoptNode() as shown below but the nodes in doc2 still
have namespace URI for the nodes as namespace A. Below is the code
( this is just to provide a gist of what I am doing, not exactly
compilable code here ) -
function Document swapNodesAndReturnNewDoc( String namespaceB,
Document doc1 )
{
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc2 = db.newDocument();
doc2.setDocumentURI( namespaceB );
Element root = doc1.getDocumentElement();
Node clonedNode = root.cloneNode(true);
doc2.adoptNode( clonedNode );
doc2.appendChild( clonedNode );
return doc2;
}
I have tried searching google and couldn't help around this. I have
tried importNode() too earlier and had the same results.. I would be
really glad to get any pointers as to where I might be going wrong.
Thanks
Dhanvi