Mobile Project Development notes (navigation menu for generating XML files dynamically)

Source: Internet
Author: User

Now the trend of software projects is gradually becoming configuration-based development, which brings great flexibility to the project, especially after the emergence of XML, configuration-based development becomes very important. In order to enable dynamic configuration of the page menu in the project, I did not save the data in the database, but wrote it in an XML file, the job of the program is to dynamically read and generate navigation menus based on the content of the XML file. (It is actually parsing XML files). I will share the content for your reference and give more comments.

The XML file format is as follows:

<? XML version = "1.0" encoding = "UTF-8"?>
<Root>
<Node name = "Project List entry" url = "projectlisttest. aspx"/>
<Node name = "Project Manager assignment" url = "pmprojectlisttest. aspx"/>
<Node name = "project information maintenance" url = "projectinfomaintaintest. aspx"/>
<Node name = "Confirm project information" url = "projectconfirmtest. aspx"/>
<Node name = "exit" url = "logintest. aspx"> </node>
</Root>

 

The following task is to dynamically generate a menu based on the configuration.

Since it is easy to implement, I don't need to describe it much. The code implementation is shown below:

Public void render ()
{
Stringbuilder sb = new stringbuilder ();
List <navigator> List = new list <navigator> ();
Loadfromxml (list );
Foreach (navigator in List)
{
SB. appendformat (@ "<a href = '{0}'> {1} </a> |", navigator. url, navigator. Name );
}
This. ltlnavigator. Text = sb. tostring (). Remove (sb. Length-1 );
}

Private void loadfromxml (list <navigator> List)
{
String Path =
Httpcontext. Current. server. mappath (
Urlhelper. getclienturl (configurationmanager. receivettings ["headnavigatorfilepath"]);
Xmldocument Doc = new xmldocument ();
Doc. Load (PATH );

Xmlnodelist nodes = Doc. selectnodes ("/root /*");
Foreach (xmlnode node in nodes)
{
Navigator navigator = new Navigator ();
Navigator. Name = node. attributes ["name"]. innertext;
Navigator. url = node. attributes ["url"]. innertext;
List. Add (Navigator );
}
}

 

The navigator class is as follows:

Protected class Navigator
{
Private field # region private field
Private string m_name;
Private string m_url;
# Endregion

Pubilc property # region pubilc Property
Public string name
{
Get
{
Return m_name;
}
Set
{
M_name = value;
}
}

Public String URL
{
Get
{
Return m_url;
}
Set
{
M_url = value;
}
}

# Endregion
}
}

 

Generated:

 

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.