471,108 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,108 software developers and data experts.

Filtering using XPath

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,

Felicity
Nov 12 '05 #1
2 2496
Hi,

Try the following,

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

Regards
Akila
Nov 12 '05 #2
Felicity wrote:
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']"

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

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by bdinmstig | last post: by
4 posts views Thread by Ben Jessel | last post: by
3 posts views Thread by serge calderara | last post: by
4 posts views Thread by Felicity | last post: by
1 post views Thread by enrico sabbadin | last post: by
1 post views Thread by Gerard Flanagan | last post: by
5 posts views Thread by DBC User | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.