Loading Items from XML
You can easily load the items of a menu from an XML source, as long as the source conforms to the following structure:
- The top level consists of a single node, called
<?xml version="1.0" encoding="utf-8" ?>
<Menu Skin="Outlook">
...
</Menu>
- Immediately below the
<Group ExpandDirection="Right" Flow="Horizontal">
...
<Group>
- Each item within a
node is represented by an - node. The attributes of the
- node correspond to the properties and custom attributes of the menu item. Any child items are contained in a
node nested within the - node:
- node. The attributes of the
<Item Text="Parent" LeftLogo="Img\parent.gif" >
<Group Width="140" Flow="Vertical">
<Item Text="Child 1" />
<Item IsSeparator="True" />
<Item Text="Child 2" />
</Group>
</Item>
To discover the way to represent a specific RadMenu feature in XML, create a RadMenu with the feature and use the RadMenu.GetXml method to get the corresponding XML string.
Once you have an XML file of the proper format, or an XML string in the proper format, you can use it to populate a RadMenu object.
Loading from an XML file
Create an XML file with content that complies with the rules described above and call the LoadContentFile method to load the items, passing in the path to the file:
RadMenu1.LoadContentFile("~/App_Data/menu.xml");
Loading from an XML string
Create a string with valid XML content (or fetch it from a database, for example) and use the LoadXML method to populate the menu from the string:
StringBuilder sb = new StringBuilder();
sb.Append("<Menu>");sb.Append(" <Group>");
sb.Append(" <Item Text='Root 1' />");
sb.Append(" <Item Text='Root 2' />");
sb.Append(" <Item Text='Root 3' />");
sb.Append(" </Group>");sb.Append(" </Menu>");
string xmlString = sb.ToString();
RadMenu1.LoadXml(xmlString);
You can also populate RadMenu from an XML file using an XmlDataSource component. When using XmlDataSource , the XML file does not have to follow the format shown in this topic. SeeBinding to Hierarchical DataSource Componentsfor details.
For a live example of loading RadMenu items from XML, see XML Definition.