zingmatter
01-21-2008, 04:36 PM
Hi
I'm not much good at xml or linq so I'm probably starting from a bad position here. I want to have menu structures stored in xml files on my .Net web site (.net 3.5, VS2008, C# coded). XML looks something like this:
<menu role="SystemAdmin">
<toplevelbutton>
<linktext>Toplevel link1</linktext>
<url>default.aspx</url>
<child1button>
<linktext>child1 link1</linktext>
<url>default.aspx</url>
<child2button>
<linktext>child2 link1</linktext>
<url>default.aspx</url>
</child2button>
</child1button>
</toplevelbutton>
<toplevelbutton>
<linktext>Toplevel link2</linktext>
<url>default.aspx</url>
<child1button>
<linktext>child1 link2</linktext>
<url>default.aspx</url>
<child2button>
<linktext>child2 link2</linktext>
<url>default.aspx</url>
</child2button>
</child1button>
</toplevelbutton>
</menu>
So using XLINQ I can get the toplevel buttons no problem (I have a couple of methods that convert the link text and url values into menu buttons).
MenuItem topLevelMenuItem = new MenuItem();
//xlinq test
String filepath = Request.MapPath("MyMenu.xml");
XElement xElement = XElement.Load(filepath);
var xquery = from c in xElement.Descendants("toplevelbutton")
where c.Element("linktext").Value.Length > 0
select new
{
linktext = c.Element("linktext").Value,
url = c.Element("url").Value
};
foreach (var q in xquery)
{
String TopLevelMenuText = q.linktext.ToString();
String TopLevelMenuURL = q.url.ToString();
//Create top level menu...
topLevelMenuItem = AddTopLevelItem(TopLevelMenuText, TopLevelMenuURL);
//PROBLEM IS HERE.....
}
The problem is while I can iterate through the <toplevelbutton /> elements, I only want to get at <childbutton1 /> etc.. for the particular node I'm currently in (and not just cycle through all instances of <childbutton1 />.
It'll be something really simple but I've spent days tralling the web for answer without success.
Any help (or pointer to the solution) much appreciated.
(I've also posted this in the ASP.NET part of this forum)
I'm not much good at xml or linq so I'm probably starting from a bad position here. I want to have menu structures stored in xml files on my .Net web site (.net 3.5, VS2008, C# coded). XML looks something like this:
<menu role="SystemAdmin">
<toplevelbutton>
<linktext>Toplevel link1</linktext>
<url>default.aspx</url>
<child1button>
<linktext>child1 link1</linktext>
<url>default.aspx</url>
<child2button>
<linktext>child2 link1</linktext>
<url>default.aspx</url>
</child2button>
</child1button>
</toplevelbutton>
<toplevelbutton>
<linktext>Toplevel link2</linktext>
<url>default.aspx</url>
<child1button>
<linktext>child1 link2</linktext>
<url>default.aspx</url>
<child2button>
<linktext>child2 link2</linktext>
<url>default.aspx</url>
</child2button>
</child1button>
</toplevelbutton>
</menu>
So using XLINQ I can get the toplevel buttons no problem (I have a couple of methods that convert the link text and url values into menu buttons).
MenuItem topLevelMenuItem = new MenuItem();
//xlinq test
String filepath = Request.MapPath("MyMenu.xml");
XElement xElement = XElement.Load(filepath);
var xquery = from c in xElement.Descendants("toplevelbutton")
where c.Element("linktext").Value.Length > 0
select new
{
linktext = c.Element("linktext").Value,
url = c.Element("url").Value
};
foreach (var q in xquery)
{
String TopLevelMenuText = q.linktext.ToString();
String TopLevelMenuURL = q.url.ToString();
//Create top level menu...
topLevelMenuItem = AddTopLevelItem(TopLevelMenuText, TopLevelMenuURL);
//PROBLEM IS HERE.....
}
The problem is while I can iterate through the <toplevelbutton /> elements, I only want to get at <childbutton1 /> etc.. for the particular node I'm currently in (and not just cycle through all instances of <childbutton1 />.
It'll be something really simple but I've spent days tralling the web for answer without success.
Any help (or pointer to the solution) much appreciated.
(I've also posted this in the ASP.NET part of this forum)