Get XML nodes cyclically

Source: Internet
Author: User
Function: Obtain the URL through the input tag (name) (the foreground gets an array in the background, which is generated by traversing web. config)
Front-end:
<script language="javascript" type="text/javascript">
function setUrl(name) {            var UrlList = <%=UrlList%>;            for (var i in UrlList ) {                var p =UrlList[i];                if(p.indexOf(name) >= 0)                {                   var url = p.substr(p.indexOf('|')+1,p.length);                   parent.location.href=url;                }            }        }
</script>

Background:
Public void geturl ()
{
Try
{
String filename = server. mappath ("Web. config ");
Xmldocument xmldoc = new xmldocument ();
Xmldoc. Load (filename );
String [] URL;
// Obtain the list of top-level nodes
Xmlnodelist topm = xmldoc. documentelement. childnodes;
Foreach (VAR top in topm)
{
Xmlelement element = top as xmlelement;
If (element! = NULL)
{
If (element. Name. tolower () = "appsettings ")
{
Xmlnodelist nodelist = element. childnodes;
Int Index = 0;
If (nodelist. Count> 0)
{
Url = new string [nodelist. Count];
Foreach (VAR node in nodelist) // read the element value xmlelement
{
Xmlelement El = node as xmlelement;
If (El! = NULL)
{
If (El. attributes ["key"]. innerxml. tolower (). Contains ("url "))
{
URL [Index] = El. attributes ["key"]. innerxml + "|" + El. attributes [1]. Value + "/default. aspx? Userid = "+ useridencode +" & Pwd = "+ pwdencode + "";
Index ++;
}
}
}
For (INT I = 0; I <index; I ++)
{
If (I = 0)
Urllist = "['" + URL [I] + "',";
Else if (I = index-1)
Urllist + = "'" + URL [I] + "']";
Else
Urllist + = "'" + URL [I] + "',";
}
}
Break;
}
}
}
}
Catch (exception)
{
Urllist = "['default. aspx ']";
}
}

  

Loading editor...

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.