当前位置:首页>正文

请教xml节点列表遍历

2023-06-09 14:20:12 互联网 未知

请教xml节点列表遍历

XmlDocument xmlDoc = new XmlDocument()
// 载入xml文件
xmlDoc.Load("1.xml")
// 找到type=C004的doc节点
XmlNode node = xmlDoc.SelectSingleNode("//doc[@type=C004]")
// 找到doc的父节点
XmlNode pnode = node.ParentNode
遍历节点:
foreach (XmlNode nd in xmlDoc.DocumentElement.ChildNodes)
{ // nd 遍历所有docctrl节点
if (nd.hasChildNodes)
{
foreach (XmlNode n in nd.ChildNodes)
{ // n 遍历所有doc和ctrl节点
string stype = n.Attributes["type"].Value
string s = n.InnerText // 节点的值
}
}
}

相关文章

随便看看