【发布时间】:2020-11-14 06:39:13
【问题描述】:
这是我的 XmlDocument
<?xml version="1.0"?>
<Config>
<Path1></Path1>
<Path2></Path2>
<Path3></Path3>
<Path4></Path4>
<Path5></Path5>
<PdfMenu>
<PdfDocument Attribute1="1" Attribute2="1.1" Attribute3="1.2" Attribute4="1.3" Attribute5="1.4" />
<PdfDocument Attribute1="2" Attribute2="2.1" Attribute3="2.2" Attribute4="2.3" Attribute5="2.4" />
<PdfDocument Attribute1="3" Attribute2="3.1" Attribute3="3.2" Attribute4="3.3" Attribute5="3.4" />
</PdfMenu>
</Config>
我目前正在使用它来寻址 <PdfMenu> 中的节点
foreach (XmlNode n in xmlDoc.ChildNodes.Item(1).ChildNodes.Item(5).ChildNodes)
现在,每次我添加另一个<Path> 时,我都必须调整Item 的数字。有没有更好的方法来做到这一点?
【问题讨论】:
标签: c# xml xmldocument