0

大家好,我有这个 xml 文档,我想提取第一个或第二个应用程序文件路径和文件名等。我试过了

DocumentElement.SelectSingleNode("/InstallerList/Installer/File_Path").InnerText

但我只得到第一个应用程序信息,从来没有第二个,我试过玩

DocumentElement.SelectNodes("//Installer")

并在它的末尾添加一个整数,这样我就可以循环浏览,但它似乎不喜欢那样。有什么想法吗?

<?xml version="1.0" encoding="utf-8"?>
<InstallerList>
 <Installer Name="First Application">
   <FilePath>C:\</FilePath>
   <Third_Parameter>etc</Third_Parameter>
   <Forth_Parameter>etc</Forth_Parameter>
 </Installer>
 <Installer Name="Second Application">
   <FilePath>etc</FilePath>
   <Third_Parameter>etc</Third_Parameter>
   <Forth_Parameter>etc</Forth_Parameter>
 </Installer>
</InstallerList>
4

1 回答 1

0

如果您只想选择一个FilePath元素,给定一些已知的键值,例如安装程序的Name属性,您可以在 XPath 中添加一个条件来缩小结果范围,如下所示:

DocumentElement.SelectSingleNode("/InstallerList/Installer[@Name='First Application']/FilePath").InnerText

或者,您可以简单地选择所有FilePath元素,然后遍历它们,如下所示:

For Each node As XmlNode In DocumentElement.SelectNodes("/InstallerList/Installer/FilePath")
    Dim path As String = node.InnerText
    ' ...
Next
于 2013-04-01T11:25:03.153 回答