我的sample.xml文件在
下面<deployment>
<definition type="xpath">
<xpath>configuration/Settings/add[@key='NetworkPath'][@value]</xpath>
<attribute>value</attribute>
<value>http://www.google.com</value>
</definition>
</deployment>
我想获取对应于xpath"配置/设置/添加[@key='NetworkPath'][@value]"的值"http://www.google.com"。我在XmlPeek任务下面写,但它不工作
<XmlPeek XmlInputPath="C:Sample.xml"
Query="configuration/Settings/add[@key='NetworkPath'][@value]">
<Output TaskParameter="Result" ItemName="Peeked" />
</XmlPeek>
<Message Text="Peeked value is @(Peeked)"/>
关于XPath可能会有一些混淆。
如果您想从Sample.xml中检索http://www.google.com,您需要应用这个查询:
<XmlPeek XmlInputPath="Sample.xml"
Query="/deployment/definition/value/text()">
<Output TaskParameter="Result" ItemName="Peeked" />
</XmlPeek>
如果你想提取路径configuration/Settings/add[@key='NetworkPath'][@value]/@value
,它对应于另一个Xml文件具有这样的形式:
<configuration>
<Settings>
<add key="NetworkPath" value="http://www.google.com"/>
</Settings>
</configuration>
查看一些XPath示例