Groups | Blog | Home
all groups > dotnet xml > december 2003 >

dotnet xml : Filtering using XPath


Felicity
12/4/2003 5:37:07 PM
Hello,

Using the following XML file, I would like to be able to
filter using an XPath
to the nodes where Menu = Yes and Form Name = frmMainMenu

<?xml version="1.0" standalone="yes"?>
<productX>
<Table Name="mnuFile">
<value>myFile</value>
<Parent></Parent>
<Menu>YES</Menu>
<Form Name="frmMainMenu" />
</Table>
<Table Name="lblTest">
<value>myTest</value>
<Parent></Parent>
<Menu>No</Menu>
<Form Name="frmMainMenu" />
</Table>
<Table Name="mnuExit">
<value>myExit</value>
<Parent></Parent>
<Menu>YES</Menu>
<Form Name="frmMainMenu" />
</Table>
</productX>

I am using the following XPath

"//Table[./@Menu=YES and ./Form/@Name = 'frmMainMenu']"

This returns no Nodes when using the following code:

strXPath = "//Table[./@Menu=YES and ./Form/@Name
= 'frmMainMenu']"

XMLNodeIterator= xmlNavigator.Select(strXPath)

After running this code the XMLNodeIterator.Count = 0.

Can anyone please help me by providing me with the correct
XPath to perform this filter.

Regards,

Saurabh Nandu
12/5/2003 11:40:24 AM
Hi,

Try the following,

"//Table[./Menu=YES and ./Form/@Name = 'frmMainMenu']"

Regards
Akila

Oleg Tkachenko
12/7/2003 2:59:32 PM
[quoted text, click to view]
Menu is element, not attribute.
Use //Table[Menu='YES' and Form/@Name = 'frmMainMenu']
or better
/productX/Table[Menu='YES' and Form/@Name = 'frmMainMenu']

--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog
AddThis Social Bookmark Button