Query XML This is the XML that I get the foreground menu
private void GetMenu (string[] cidlist, string[] idlist)
{
Get menu File
String spath = System.Web.HttpContext.Current.Request.MapPath ("Menu/menufile.xml");
Load
Xml. Load (spath);
for (int i = 0; i < cidlist. Length; i++)
{
XmlNode Thisnode = XML. Documentelement.selectsinglenode ("/menus/menu[@cid =" + cidlist[i]. ToString () + "]");
if (Thisnode! = null)
{
HTML + = "<li class= ' ><a href= ' javascript:; ' ><i class= ' "+ thisnode.attributes[" icon "]. Value + "' ></i> <span class= ' title ' >" + thisnode.attributes["heard"]. Value + "</span><span class= ' arrow ' ></span></a><ul class= ' sub-menu ' >";
for (int j = 0; J < Idlist. Length; J + +)
{
XmlNode thisNode1 = XML. Documentelement.selectsinglenode ("/menus/menu[@cid =" + cidlist[i]. ToString () + "]/li[@id =" + idlist[j]. ToString () + "]");
if (thisNode1! = null)
{
HTML + = "<li><a onclick= ' gotosrc (this) ' src= '" + thisnode1.attributes["src"]. Value + "' target= ' main ' >" + thisnode1.attributes["tittle"]. Value + "</a></li>";
}
Else
{
Continue
}
}
HTML + = "</ul></li>";
}
}
}
Add to:
String name = Context. request.form["Name"]. ToString ();
String strcid = context. request.form["Strcid"]. ToString ();
String Strtid = context. request.form["Strtid"]. ToString ();
XmlDocument xml = new XmlDocument ();
String spath = System.Web.HttpContext.Current.Request.MapPath (".. /menu/rolefile.xml ");
XML. Load (spath);
XmlNode root = XML. selectSingleNode ("Roles");
XmlNodeList xnl = root. ChildNodes;
BOOL flag = FALSE;
foreach (XmlNode item in XNL)
{
XmlElement xe = (XmlElement) item;
if (XE. GetAttribute ("roleName") = = name)
{
flag = true;
}
Else
{
continue;
}
}
if (flag = = False)
{
XmlElement xe1 = XML. createelement ("role");
Xe1. SetAttribute ("RoleName", name);
Xe1. SetAttribute ("CID", strcid);
Xe1. SetAttribute ("PList", Strtid);
Root. AppendChild (XE1);
XML. Save (spath);
Context. Response.Write ("OK");
}
Else
{
context. Response.Write ("This role already exists!");
}
Delete:
String roleName = context. request.form["RoleName"]. Trim (). ToString ();
String spath = System.Web.HttpContext.Current.Request.MapPath (".. /menu/rolefile.xml ");
XmlDocument xmldoc = new XmlDocument ();
Xmldoc.load (spath);
XmlNodeList XNL = Xmldoc.selectsinglenode ("Roles"). ChildNodes;
String flag = "NO";
foreach (XmlNode xn in xnl)
{
XmlElement XE = (XmlElement) xn;
if (XE. GetAttribute ("roleName") = = RoleName)
{
Xe. RemoveAll ();//delete the entire contents of the node
Xn. RemoveAll (); Delete the node
Flag = "OK";
Break
}
}
if (flag = = "OK")
{
Xmldoc.save (spath);
Context. Response.Write (flag);
}
else {
Context. Response.Write (flag);
}
Modify and add the same is to re-assign a value to save the document
. NET operations XML (1) Add, delete, modify, query