#region 遍历XML文件 调用方法 调用方法 XmlFileAllNodes(Server.MapPath("treeout.xml"), "")
/// <summary>
/// 添加栏目的临时级别
/// </summary>
int XmlFileAllNodesCloumnLvTemp = 0;
/// <summary>
/// 添加栏目的临时ID
/// </summary>
int XmlFileAllNodesColumnsIDTemp = 0;
/// <summary>
/// 添加栏目函数
/// </summary>
/// <param name="xmlpath">XML栏目文件</param>
/// <param name="XmlData">为空 "" </param>
/// <![CDATA[调用方法 XmlFileAllNodes(Server.MapPath("treeout.xml"), "")]]>
/// <returns></returns>
public string XmlFileAllNodes(string xmlpath, String XmlData)
{
System.Xml.XmlDataDocument MyXml = new System.Xml.XmlDataDocument();
if (XmlData == "")
{
MyXml.Load(xmlpath);//得到XML数据
}
else
{
MyXml.LoadXml(XmlData);
}
for (int i = 0; i < MyXml.DocumentElement.ChildNodes.Count; i++)
{
try
{ //得到树状结构
if (XmlFileAllNodesCloumnLvTemp == 0)//一级节点
{
System.Web.HttpContext.Current.Response.Write(TextData.EStr(XmlFileAllNodesCloumnLvTemp, " ") + XmlFileAllNodesColumnsIDTemp + MyXml.DocumentElement.ChildNodes[i].Attributes.GetNamedItem("Cont").Value + XmlFileAllNodesCloumnLvTemp + " <br/>");
}
else
{
System.Web.HttpContext.Current.Response.Write(TextData.EStr(XmlFileAllNodesCloumnLvTemp, " ") + XmlFileAllNodesColumnsIDTemp + MyXml.DocumentElement.ChildNodes[i].Attributes.GetNamedItem("Cont").Value + XmlFileAllNodesCloumnLvTemp + " <br/>");
//如果是子节点
}
XmlFileAllNodesColumnsIDTemp += 1;
XmlFileAllNodesCloumnLvTemp++;
XmlFileAllNodes(xmlpath, MyXml.DocumentElement.ChildNodes[i].OuterXml);//得到这个XML文件下的所有子节点
XmlFileAllNodesCloumnLvTemp--;
}
catch (System.Xml.XmlException)//这里如是最下层就不进行下一次的调用自己了
{
}
}
return "";
}
#endregion
/// <summary>
/// 添加栏目的临时级别
/// </summary>
int XmlFileAllNodesCloumnLvTemp = 0;
/// <summary>
/// 添加栏目的临时ID
/// </summary>
int XmlFileAllNodesColumnsIDTemp = 0;
/// <summary>
/// 添加栏目函数
/// </summary>
/// <param name="xmlpath">XML栏目文件</param>
/// <param name="XmlData">为空 "" </param>
/// <![CDATA[调用方法 XmlFileAllNodes(Server.MapPath("treeout.xml"), "")]]>
/// <returns></returns>
public string XmlFileAllNodes(string xmlpath, String XmlData)
{
System.Xml.XmlDataDocument MyXml = new System.Xml.XmlDataDocument();
if (XmlData == "")
{
MyXml.Load(xmlpath);//得到XML数据
}
else
{
MyXml.LoadXml(XmlData);
}
for (int i = 0; i < MyXml.DocumentElement.ChildNodes.Count; i++)
{
try
{ //得到树状结构
if (XmlFileAllNodesCloumnLvTemp == 0)//一级节点
{
System.Web.HttpContext.Current.Response.Write(TextData.EStr(XmlFileAllNodesCloumnLvTemp, " ") + XmlFileAllNodesColumnsIDTemp + MyXml.DocumentElement.ChildNodes[i].Attributes.GetNamedItem("Cont").Value + XmlFileAllNodesCloumnLvTemp + " <br/>");
}
else
{
System.Web.HttpContext.Current.Response.Write(TextData.EStr(XmlFileAllNodesCloumnLvTemp, " ") + XmlFileAllNodesColumnsIDTemp + MyXml.DocumentElement.ChildNodes[i].Attributes.GetNamedItem("Cont").Value + XmlFileAllNodesCloumnLvTemp + " <br/>");
//如果是子节点
}
XmlFileAllNodesColumnsIDTemp += 1;
XmlFileAllNodesCloumnLvTemp++;
XmlFileAllNodes(xmlpath, MyXml.DocumentElement.ChildNodes[i].OuterXml);//得到这个XML文件下的所有子节点
XmlFileAllNodesCloumnLvTemp--;
}
catch (System.Xml.XmlException)//这里如是最下层就不进行下一次的调用自己了
{
}
}
return "";
}
#endregion
XML文件





