Groups | Blog | Home
all groups > dotnet xml > may 2005 >

dotnet xml : xpath for children


helpful sql
5/26/2005 3:01:46 PM
Hi all,
Following is a part of an Xml document I am having problems with. I have
a XmlNode variable in my C# application that referes to the mytable node of
the following Xml. Now I need to get all children of mytable node from the
ns0 namespace(myfield1 and myfield2 in this case) using the XmlNode object.
I need a help with Xpath query to achieve this.

Do you think the following statement would work?
mytablenode.SelectNodes("descendant::ns0:*",mynamespacemanager);



<ns0:mydataset>
<ns0:mytable>
<w:p>
<ns0:myfield1>value</ns0:myfield1>
</w:p>
<w:p>
<ns0:myfield2>value</ns0:myfield2>
</w:p>
</ns0:mytable>
</ns0:mydataset>


Thanks in advance.

Martin Honnen
5/27/2005 12:00:00 AM


[quoted text, click to view]


[quoted text, click to view]

The expression is fine as long as the prefix ns0 is bound to the right
URI (e.g. you do
mynamespacemanager.Add("ns0", "namespaceURI")
before).
The shortcut notation for the XPath is
".//ns0:*"


[quoted text, click to view]

Also note that your subject and your explanation says you are looking
for children of the mytable element but the XPath correctly looks for
descendant nodes (as that is what myfield1/myfield2 elements are.


--

Martin Honnen --- MVP XML
AddThis Social Bookmark Button