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 ]

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

(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

I don't know Xalan's XPathAPI, but I wonder how it is resolving

//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


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

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