Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XPath help needed

Status
Not open for further replies.

PGoRule

Programmer
Jul 26, 2006
438
IN
I have one XML file as:
Code:
<MenuItems>
  <Menu>
    <Caption>&amp;Set Field Identifier Prefix</Caption>
    <Action>SetFieldIdentifierPrefix</Action>
  </Menu>
  <Menu>
    <Caption>&amp;Remove Field Identifier Prefix</Caption>
    <Action>RemoveFieldIdentifierPrefix</Action>
  </Menu>
</MenuItems>

I want to iterate through all <Menu> items to show them on toolbar. So in c# I have:
Code:
private const string CAP = "/Caption";
private const string ACT = "/Action";
private const string XPATH_STRING = "/MenuItems/Menu";

XPathDocument XPathDoc = new XPathDocument(FileName);
XPathNavigator Navigator = XPathDoc.CreateNavigator();

string Caption = Navigator.SelectSingleNode(XPATH_STRING + CAP).Value;
string Action = Navigator.SelectSingleNode(XPATH_STRING + ACT).Value;
AddButton(Caption, Action);

This gives me only first menu. How should I iterate thro' all <Menu> in <MenuItems> so that I can have all menus on toolbar.

Thanx...
Prashant

Sharing the best from my side...

--Prashant--
 
XPathDoc.SelectSingleNode("\\MenuItems");

XmlNode[] menuitems = XPathDoc.SelectNodes("Menu");

foreach (XmlNode item in menuitems)
{
Console.WriteLine(item.SelectSingleNode("Caption").Value);
Console.WriteLine(item.SelectSingleNode("Action").Value);
}



Something to that effect.
 
Thanx for your reply.
But I am not getting SelectSingleNode method with XPathDoc object.

What I'm missing in this context?

Thanx...
Prashant

Sharing the best from my side...

--Prashant--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top