OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] Problem with cloneNode

[ Lists Home | Date Index | Thread Index ]

Please see my comments below

		-----Original Message-----
		From:	Ronald Bourret [mailto:rpbourret@rpbourret.com]
		Sent:	Tuesday, April 09, 2002 5:50 PM
		To:	Sean Zhang; xml-dev
		Subject:	Re: [xml-dev] Problem with cloneNode

		Sean Zhang wrote:
		> 
		> Here is the sample of my code:
		> 
		> Original node is:
		>                 <level1 attr1="1">
		>                         <level2 attr2="2.1"/>
		>                        <level2 attr2="2.2"/>
		> </level1>
		> 
		> Node newNode = originalNode.cloneNode(true);
		> NewNode.getAttributes.getNamedItem("attr1") = "3";

		Why does this even compile? The return value of
getNamedItem() is a
		Node. How can you set it to a String? Also, the identifier
in the second
		line (NewNode) is different from the identifier in the first
line
		(newNode).

		The line NewNode.getAttributes.getNamedItem("attr1") = "3";
should be NewNode.getAttributes.getNamedItem("attr1").setNodeValue("3");

		(I'm assuming the code is Java, although I'm pretty sure the
same
		problems would apply to C++.)

		it is Java

		> Then I used Xalan Xpath syntax to get the nested level2
nodes
		> Node newLevel2 = XPathAPI.selectSingleNode(newNode,
"//level2");
		> NewLevel2.getAttributes.getNamedItem("attr2") = "2.1";
		> NewLevel2 = XPathAPI.selectSingleNode(newNode,
"//level2[last()]");
		> NewLevel2.getAttributes.getNamedItem("attr2") = "2.2";

		Do you mean "4.1" and "4.2"? (The same compilation problems
apply as
		well.)

		it should say "4.1" and "4.2" .  Also need to change the
syntax where setting the attributes values 
	
NewLevel2.getAttributes.getNamedItem("attr2").setNodeValue("4.1");
	
NewLevel2.getAttributes.getNamedItem("attr2").setNodeValue("4.2");

		I don't know Xalan's XPathAPI, but I wonder how it is
resolving
		"//level2".


		//level2 means to search for all level2 elements in the
document. The
		question is, what is the document here? Does newNode define
the root of
		the search? Or does Xalan call
		newNode.getOwnerDocument().getDocumentElement() and search
from there?
		The second case would explain the behavior you are seeing.

		I have to look into how Xalan search for the level2
elements.  If it gets the root of the owner document and search from there,
then it explains all.
		Anyone can shed some light on Xalan's XPathAPI?

		> Is it possible that it is Xalan which creates the problem?
I used Xalan
		> Xpath syntax because I cannot find an easy way in Xerces
to get the nested
		> nodes.  The getChildNodes() method returns not only
element nodes but all
		> kinds of nodes.  Anyone can recommend an easy way to get
to the child
		> element nodes?

		-- Ron




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS