private void loadxml()
{
xmldoc = new XmlDocument();
xmldoc.Load(Server.MapPath("../xml/info.xml"));
}
private void showxml()
{
loadxml();
XmlNode node = xmldoc.SelectSingleNode("user");
XmlNodeList nlist = node.ChildNodes;
foreach (XmlNode xn in nlist)
{
XmlElement el = (XmlElement)xn;
Console.WriteLine(el.GetAttribute("name"));
Console.WriteLine(el.GetAttribute("sex"));
XmlNodeList list1 = el.ChildNodes;
foreach (XmlNode node2 in list1)
{
Console.WriteLine(node2.InnerText);
}
}
}
看这样写有什么不妥呢,运行程序时候,页面中一条数据也不会出来……
是那里学错了吗?
我的xml文件是这样的:
<user>
<person name="淇河" sex="男" age="30">
<pass>123456</pass>
<Address>安阳林州</Address>
</person>
</user>
一只甜甜圈
江户川乱折腾