Groups | Blog | Home
all groups > dotnet xml > april 2004 >

dotnet xml : SelectSingleNode and XPath question


Dave
4/20/2004 12:11:03 PM
Is it possible to get

<codes><code id="4"><name>abc</name></code></codes

from the XML below in single SelectSingleNode/xPath expression step OR is going to have to be a multi=step process of using SelectNodes with an XPath expression to return all the nodes with "code id = 4", iterate the NodeList, re-build the XML string and wrap it with "<codes>" again?

I wasn't sure if you can somehow return the parent node when using xPath to find certain nodes or to phrase it differently, return a parent node with only certain child nodes that meet the xPath expression's criteria

Oleg Tkachenko [MVP]
4/21/2004 10:02:34 AM
[quoted text, click to view]

Thats couple of lines in XSLT.

[quoted text, click to view]

Both are possible. To return parent node use "..", e.g. //C/..
returns parent nodes of all C elements in document. Otherwise //*[C]
returns all elements, who have C child child.
--
Oleg Tkachenko [XML MVP, XmlInsider]
AddThis Social Bookmark Button