1

My sample.xml file is below

<deployment>
     <definition type="xpath">
      <xpath>configuration/Settings/add[@key='NetworkPath'][@value]</xpath>
  <attribute>value</attribute>
  <value>http://www.google.com</value>
 </definition>
</deployment>

I want to fetch the value "http://www.google.com" corresponsing to xpath "configuration/Settings/add[@key='NetworkPath'][@value]". I am writing below XmlPeek task but it is not working

 <XmlPeek XmlInputPath="C:\Sample.xml"
         Query="configuration/Settings/add[@key='NetworkPath'][@value]">
  <Output TaskParameter="Result" ItemName="Peeked" />
</XmlPeek>
<Message Text="Peeked value is @(Peeked)"/>
Ravneet
  • 11
  • 4

1 Answers1

1

There might be some confusion about XPath.

If you want to retrieve htttp://www.google.com from Sample.xml you need to apply this query:

<XmlPeek XmlInputPath="Sample.xml"
         Query="/deployment/definition/value/text()">
  <Output TaskParameter="Result" ItemName="Peeked" />
</XmlPeek>

If you want to extract the path configuration/Settings/add[@key='NetworkPath'][@value]/@value it corresponds to another Xml file having this form:

<configuration>
    <Settings>
        <add key="NetworkPath" value="http://www.google.com"/> 
    </Settings>
</configuration>

Check out some XPath examples.

Fabian
  • 1,886
  • 14
  • 13
  • Thank you Fabian. I understood what you mean. – Ravneet Aug 07 '15 at 09:57
  • Thank you Fabian. I understood what you mean. The way I want is correctly being fetched by third Party tool "Final Builder". so, i thought there must be a way to do same with msbuild. Let's see if someone else has answer or a way to do this – Ravneet Aug 07 '15 at 10:04
  • You can do it with msbuild but you need to change the XmlInputPath and use the real xml file instead of "Sample.xml" – Fabian Aug 07 '15 at 10:10