How do I bind a menu to an XML document?

Problem Statement

Users navigate through application features using a command menu structure that organizes their tasks under common headings.  Submenus cascade down and to the right or left.  An example would be a policy claims administrative application where customer service representatives have a set of canned transactions they're authorized to perform to service various clients: policyholders, beneficiaries, and insureds. In addition to menu commands familiar to most users, each of these client types can be associated with a separate list of actions a customer service representation can take.

Your application has represented this structure in an XML document, where the names of each menu and submenu are the local names of the XML elements.  This XML document might be accessed from an external file or retrieved from a Web service interface.  This arrangement may have been made to allow changes in the list of supported transactions without requiring the application to be redeployed.

Infragistics Solutions

ASP.NET     Windows Forms    
 

Add a WebMenu control and an XmlDataSource control to your Web page.  You will configure the XmlDataSource to wrap your XML document that describes the menu's structure using either the DataFile property (if the XML document is in an external file) or the Data property (if the XML document has been read into a string, such as from a Web service call).  You may optionally specify an XSLT style sheet that the XmlDataSource will use to adapt your XML document into an element content model compatible for binding with WebTree, or an XPath filter expression to obtain the menu structure from a node subset contained within an XML document that may contain more information than just the menu structure.  WebMenu assumes the form of the menu structure defined by the XML after you have set the WebMenu's DataSource property to the XmlDataSource control, and the WebMenu has data bound.

WebMenu item labels created from the XmlDataSource default to using the tag names of the elements mirroring the hierarchical structure of your XML document.  If the names for your menu items contain embedded whitespace, or otherwise do not correspond to the tag names of the elements, then you will need to create ItemBindings associating an attribute (or simple text content) from each XML document element to the properties of a WebMenu item.

Other Solutions in the Data Binding Category

More Scenario Solutions...