[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Problem with cloneNode

  • To: Sean Zhang <Sean.Zhang@i...>, xml-dev <xml-dev@l...>
  • Subject: Re: Problem with cloneNode
  • From: Ronald Bourret <rpbourret@r...>
  • Date: Tue, 09 Apr 2002 15:50:03 -0700
  • References: <93B9C6964541D3119F350008C7F4455705161A1C@d...>

clonenode problem
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).

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

> 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.)

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.

> 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.