方法體
using System;
using System.XML;
using System.Configuration;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace XMLSize
{
public struct strRestric
{
public string msgPage;
public string msgPrompt;
public int size;
}
public class XMLRestrict
{
public static strRestric res;
public XMLRestrict()
{
res.msgPage="";
res.msgPrompt="";
res.size=0;
}
public static object Restrict(string XMLPathName,string nodeID,strRestric res)
{
int NodeNum=1;
string path="";
path =ConfigurationSettings.APPSettings.Get(XMLPathName).ToString();
path+="Restrict.XML";
try
{
XmlDocument xmlDoc=new XMLDocument();
XMLDoc.Load(path);
XmlNodeList nodeList=XMLDoc.SelectSingleNode("Tree").ChildNodes;
foreach(XMLNode xn in nodeList)
{
XmlElement xe=(XMLElement)xn;
if(xe.Name=="Node")
{
XMLNodeList nls=xe.ChildNodes;
foreach(XMLNode xn1 in nls)
{
XmlElement xe2=(XMLElement)xn1;
if(xe2.Name=="PageId")
{
if(xe2.InnerText==nodeID)
{
XmlNode xnChild=(XMLNode)xe2;
XMLNode child=xnChild.ParentNode.ChildNodes[NodeNum+1];
XmlElement xeChild=(XMLElement)child;
string Id=xeChild.GetAttribute("value");
int Pid=int.Parse(Id);
res.msgPage=child.InnerText.ToString();
res.msgPrompt=xnChild.ParentNode.ChildNodes[NodeNum+2].InnerText.ToString();
res.size=Pid;
return res;
}
break;
}
}
}
}
}
catch
{}
return null;
}