You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Tom Wnuk <tw...@earthlink.net> on 2000/05/05 17:00:07 UTC

importNode() Problem

I'm trying to utilize importNode() as defined below.  I'm using xerces
v1.0.3 and the it appears the importNode is not working.  

What am I doing wrong?

==================
        String sXML1 = "<?xml version=\"1.0\" ?>" +
                        "<TEST><ResponseType>XML</ResponseType>" +
                        "<StyleSheet>login.xsl</StyleSheet>" +
                        "</TEST>";
                        
        try
        {
            Document doc1 = XMLHelper.getDocument(sXML1);
		    Element eRoot = doc1.getDocumentElement();        
            NodeList nlTmp = eRoot.getElementsByTagName("ResponseType");
            Node node = nlTmp.item(0);
            
            Document doc2 = XMLHelper.getDocument();
		    Element eNewRoot  = doc2.createElement("TEST");
		    doc2.appendChild(eNewRoot);		
            
            doc2.importNode(node, true);
            
            String sDoc2 = XMLHelper.makeStringFromDOM(doc2);
            
            System.out.println("sDoc=\n" + sDoc2);
        }

==================

Thanks 
Tom

Tom Wnuk
twnuk@earthlink.net
twnuk@hotmail.com


Re: importNode() Problem

Posted by Sean Kelly <ke...@mail2a.jpl.nasa.gov>.
> I'm afraid importNode is broken in 1.0.3. I don't really remember when I
> fixed it but I think it's after that. So, either you get the latest
> version from CVS or you wait for the new release to come out (very very
> soon now!). Sorry, I can't help you more.

It's working for me, and I'm using xerces 1.0.3.

The problem is this: importNode *returns* a new Node object whose owning
document is the target doc object.  You then have to add that returned node
to your target doc at the correct location.  This should work:

Node importedNode = doc2.importNode(node, true);
eNewRoot.appendChild(importedNode);

Take care,
--Sean


RE: importNode() Problem

Posted by Tom Wnuk <tw...@earthlink.net>.
It may not be working as it's suppose to but it returns a Node that is now
owned by the target doc and that's good enough for now.

I'll keep my I out for the new release.

Thanks
Tom

-----Original Message-----
From: Arnaud Le Hors [mailto:lehors@us.ibm.com]
Sent: Friday, May 05, 2000 9:51 AM
To: general@xml.apache.org
Subject: Re: importNode() Problem


I'm afraid importNode is broken in 1.0.3. I don't really remember when I
fixed it but I think it's after that. So, either you get the latest
version from CVS or you wait for the new release to come out (very very
soon now!). Sorry, I can't help you more.
--
Arnaud  Le Hors - IBM Cupertino, XML Technology Group

---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org



Re: importNode() Problem

Posted by Arnaud Le Hors <le...@us.ibm.com>.
I'm afraid importNode is broken in 1.0.3. I don't really remember when I
fixed it but I think it's after that. So, either you get the latest
version from CVS or you wait for the new release to come out (very very
soon now!). Sorry, I can't help you more.
-- 
Arnaud  Le Hors - IBM Cupertino, XML Technology Group

RE: importNode() Problem

Posted by Tom Wnuk <tw...@earthlink.net>.
Well, I have resolved my problem.

Whether it is suppose to work like this I'm no longer sure.  After reading
the DOM spec again for importNode(), it doesn't say that it will actually
update the target DOM via the import process.  My understanding is that it
simply returns the node which is now owned by the target DOM.  This may be a
side-effect but it's enough to allow me to place this node in the target DOM
as opposed to letting the import just append it.  It actually saves me from
having to build a new DOM, now I can simply call replaceNode() instead.

If I'm assuming in error or have made a big mistake, please let me know.

Thanks again for everyone's help.
Tom


>  -----Original Message-----
> From: 	Tom Wnuk [mailto:twnuk@earthlink.net] 
> Sent:	Friday, May 05, 2000 9:18 AM
> To:	Apache XML General-Help
> Subject:	RE: importNode() Problem
> 
> Thank-you so much for responding so quickly.  I tried adding cloneNode()
> but unfortunately it didn't correct the problem.
> 
> I'm at a loss and I really don't want to code another solution since
> you've already done it.  
> 
> Any other ideas would be most appreciated.
> 
> Thanks
> Tom
> 
> Tom Wnuk
> 
> 
> 	 -----Original Message-----
> 	From: 	Linda Derezinski [mailto:linda@interfacecontrol.com] 
> 	Sent:	Friday, May 05, 2000 8:19 AM
> 	To:	general@xml.apache.org; twnuk@earthlink.net
> 	Subject:	RE: importNode() Problem
> 
> 	The node passed to importnode cannot have a parent.  In your
> example, node is a member of document sXML1.
> 	Just missing the call to cloneNode().
> 
> 
> 		Node newNode = node.cloneNode (true);
> 	            doc2.importNode(newNode, true);
> 
> 	- Linda Derezinski
> 		 -----Original Message-----
> 		From: 	Tom Wnuk [mailto:twnuk@earthlink.net] 
> 		Sent:	Friday, May 05, 2000 11:00 AM
> 		To:	Apache XML General-Help
> 		Subject:	importNode() Problem
> 
> 		I'm trying to utilize importNode() as defined below.  I'm
> using xerces v1.0.3 and the it appears the importNode is not working.  
> 
> 		What am I doing wrong?
> 
> 		==================
> 		        String sXML1 = "<?xml version=\"1.0\" ?>" +
> 	
> "<TEST><ResponseType>XML</ResponseType>" +
> 		                        "<StyleSheet>login.xsl</StyleSheet>"
> +
> 		                        "</TEST>";
> 		                        
> 		        try
> 		        {
> 		            Document doc1 = XMLHelper.getDocument(sXML1);
> 				    Element eRoot =
> doc1.getDocumentElement();        
> 		            NodeList nlTmp =
> eRoot.getElementsByTagName("ResponseType");
> 		            Node node = nlTmp.item(0);
> 		            
> 		            Document doc2 = XMLHelper.getDocument();
> 				    Element eNewRoot  =
> doc2.createElement("TEST");
> 				    doc2.appendChild(eNewRoot);		
> 		            
> 		            doc2.importNode(node, true);
> 		            
> 		            String sDoc2 =
> XMLHelper.makeStringFromDOM(doc2);
> 		            
> 		            System.out.println("sDoc=\n" + sDoc2);
> 		        }
> 
> 		==================
> 
> 		Thanks 
> 		Tom
> 
> 		Tom Wnuk
> 		twnuk@earthlink.net
> 		twnuk@hotmail.com
> 		 << File: ATT00006.txt >>  << File: ATT00031.txt >> 

RE: importNode() Problem

Posted by Tom Wnuk <tw...@earthlink.net>.
Thank-you so much for responding so quickly.  I tried adding cloneNode() but
unfortunately it didn't correct the problem.

I'm at a loss and I really don't want to code another solution since you've
already done it.  

Any other ideas would be most appreciated.

Thanks
Tom

Tom Wnuk


>  -----Original Message-----
> From: 	Linda Derezinski [mailto:linda@interfacecontrol.com] 
> Sent:	Friday, May 05, 2000 8:19 AM
> To:	general@xml.apache.org; twnuk@earthlink.net
> Subject:	RE: importNode() Problem
> 
> The node passed to importnode cannot have a parent.  In your example, node
> is a member of document sXML1.
> Just missing the call to cloneNode().
> 
> 
> 	Node newNode = node.cloneNode (true);
>             doc2.importNode(newNode, true);
> 
> - Linda Derezinski
> 	 -----Original Message-----
> 	From: 	Tom Wnuk [mailto:twnuk@earthlink.net] 
> 	Sent:	Friday, May 05, 2000 11:00 AM
> 	To:	Apache XML General-Help
> 	Subject:	importNode() Problem
> 
> 	I'm trying to utilize importNode() as defined below.  I'm using
> xerces v1.0.3 and the it appears the importNode is not working.  
> 
> 	What am I doing wrong?
> 
> 	==================
> 	        String sXML1 = "<?xml version=\"1.0\" ?>" +
> 	                        "<TEST><ResponseType>XML</ResponseType>" +
> 	                        "<StyleSheet>login.xsl</StyleSheet>" +
> 	                        "</TEST>";
> 	                        
> 	        try
> 	        {
> 	            Document doc1 = XMLHelper.getDocument(sXML1);
> 			    Element eRoot = doc1.getDocumentElement();
> 
> 	            NodeList nlTmp =
> eRoot.getElementsByTagName("ResponseType");
> 	            Node node = nlTmp.item(0);
> 	            
> 	            Document doc2 = XMLHelper.getDocument();
> 			    Element eNewRoot  = doc2.createElement("TEST");
> 			    doc2.appendChild(eNewRoot);		
> 	            
> 	            doc2.importNode(node, true);
> 	            
> 	            String sDoc2 = XMLHelper.makeStringFromDOM(doc2);
> 	            
> 	            System.out.println("sDoc=\n" + sDoc2);
> 	        }
> 
> 	==================
> 
> 	Thanks 
> 	Tom
> 
> 	Tom Wnuk
> 	twnuk@earthlink.net
> 	twnuk@hotmail.com
> 	 << File: ATT00006.txt >> 

RE: importNode() Problem

Posted by Linda Derezinski <li...@interfacecontrol.com>.
The node passed to importnode cannot have a parent.  In your example, node
is a member of document sXML1.
Just missing the call to cloneNode().


	Node newNode = node.cloneNode (true);
            doc2.importNode(newNode, true);

- Linda Derezinski
>  -----Original Message-----
> From: 	Tom Wnuk [mailto:twnuk@earthlink.net] 
> Sent:	Friday, May 05, 2000 11:00 AM
> To:	Apache XML General-Help
> Subject:	importNode() Problem
> 
> I'm trying to utilize importNode() as defined below.  I'm using xerces
> v1.0.3 and the it appears the importNode is not working.  
> 
> What am I doing wrong?
> 
> ==================
>         String sXML1 = "<?xml version=\"1.0\" ?>" +
>                         "<TEST><ResponseType>XML</ResponseType>" +
>                         "<StyleSheet>login.xsl</StyleSheet>" +
>                         "</TEST>";
>                         
>         try
>         {
>             Document doc1 = XMLHelper.getDocument(sXML1);
> 		    Element eRoot = doc1.getDocumentElement();        
>             NodeList nlTmp = eRoot.getElementsByTagName("ResponseType");
>             Node node = nlTmp.item(0);
>             
>             Document doc2 = XMLHelper.getDocument();
> 		    Element eNewRoot  = doc2.createElement("TEST");
> 		    doc2.appendChild(eNewRoot);		
>             
>             doc2.importNode(node, true);
>             
>             String sDoc2 = XMLHelper.makeStringFromDOM(doc2);
>             
>             System.out.println("sDoc=\n" + sDoc2);
>         }
> 
> ==================
> 
> Thanks 
> Tom
> 
> Tom Wnuk
> twnuk@earthlink.net
> twnuk@hotmail.com
>  << File: ATT00006.txt >>