Manipulating Web pages with XML

Source: Internet
Author: User

The settings of the XML can be used to set up the page and jump between pages.

This example reads the data from the XML and then binds to the control, which can be used to jump between pages based on the URL of the content being read.

1, the first need to write XML. For example:

Menu.xml--->

<?xml version= "1.0" encoding= "Utf-8"?> <Menu> <!--<TopMenu> <menuitem name= "Listairline" Description= "Basic Management" url= "/backstage/basicmanagement/management.aspx"/> <menuitem Name= "ListOrders" description= "Order Management" url= "/backstage/ordermanagement.html"/> <menuitem name= "Listinternaluser" Description= " Background user Management "Url="/backstage/internalusermanagement/management.aspx "/> </TopMenu>-->

    <topmenu name= "Basedata" description= "Basic Management" url= "/backstage/basicmanagement/management.aspx" >         <subtitle title= "Basic Management" >              <leftmenuitem name= "Basedata_airline" description= "domestic route" url= "/backstage/" Basicmanagement/management.aspx? Type=airline "/>             <leftmenuitem name=" Basedata_airlineint "description=" International Route "url="/backstage/basicmanagement/management.aspx? Type=airlineint "/>             <leftmenuitem name=" Basedata_aircompany "description=" Airline "url="/backstage/basicmanagement/management.aspx? Type=aircompany "/>             <leftmenuitem name=" Basedata_airport "description=" Airport Management "Url="/backstage/basicmanagement/management.aspx? Type=airport "/>             <leftmenuitem name= "Basedata_plane" Description= "Aircraft Information" Url= " /backstage/basicmanagement/management.aspx? Type=plane "/>             <leftmenuitem name=" Basedata_favortype "description=" offer Information "Url="/backstage/basicmanagement/management.aspx? Type=favortype "/>         </SubTitle>     </topmenu ></Menu>

2. It is necessary to put the written menu.xml in Web. config to facilitate its invocation

<appSettings>
<add key= "Menuconfig" value= "/configuration/menu/menu.xml"/>

</appSettings>

3. menu.xml files can be obtained by ConfigurationManager

public static ienumerable<dynamic> Getmainmenus ()
{
String path = configurationmanager.appsettings["Menuconfig"];
Path = HttpContext.Current.Server.MapPath (path);
var xElement = xelement.load (path). Elements ("Topmenu");
var xelements = xElement as ilist<xelement>?? Xelement.tolist ();
if (Xelements.any ())
{
var menuconfig = from P in xelements
Select P;
var menus = new list<dynamic> ();
foreach (Var menu in Menuconfig)
{
Menus. Add (New {Name = menu. Firstattribute.value, Description = menu. Attribute ("Description"). Value, Url = menu. Attribute ("Url"). Value});
}
return menus;
}
return null;
}

4. Bind the read-out data to the appropriate control

Menulist.datasource = menus;
Menulist.databind ();

Because the <a href> property is in the bound ListView, the URL that is given the corresponding bound value jumps directly. The code is as follows:

<asp:listview runat= "Server" id= "Menulist" >
<ItemTemplate>
<li id= ' <% #Eval ("Name")%> ' ><a href= ' <% #Eval ("Url")%> ' >
<% #Eval ("Description")%></a> </li>
</ItemTemplate>
</asp:ListView>

PS: <% #Eval ()%> the value to reach the bound field

Manipulating Web pages with XML

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.