XML文档如下:
<?xml version="1.0" standalone="yes"?>
< ItemData>
< AccFirst>
<Table>
<ChName>职业</ChName>
<ChNValue>刀客|剑士|枪客|医生|弓手|刺客</ChNValue>
<Need>1</Need>
</Table>
<Table>
<ChName>等级</ChName>
<ChNValue></ChNValue>
<Need>1</Need>
</Table>
<Table>
<ChName>性别</ChName>
<ChNValue>男|女</ChNValue>
<Need>1</Need>
</Table>
< /AccFirst>
< AccSecond>
<Table>
<ChName>游戏账号</ChName>
<ChNValue></ChNValue>
<Need>1</Need>
</Table>
<Table>
<ChName>游戏密码</ChName>
<ChNValue></ChNValue>
<Need>1</Need>
</Table>
C#代码如下:
XmlDocument objDoc = new XmlDocument();
objDoc.Load(xmlPath);
string LayerName = "/ItemData/AccFirst";//指定读取的节点
//LayerName = "/ItemData/AccSecond";
XmlNode root = objDoc.SelectSingleNode(LayerName);
XmlNodeList childlist = root.ChildNodes;
for (int i = 0; i < childlist.Count; i++)
{
foreach (XmlNode xnl in childlist[i].ChildNodes)
{
XmlElement xe = (XmlElement)xnl;
Response.Write(xnl.Name + ":" + xnl.InnerText);//纯文本
Response.Write("<br>");
}
Response.Write("<hr>");
}
如果重根节点读取用XmlReader流方式读取就可以