Daniel Hayman
Daniel Hayman

Reputation: 11

Using xpath.bat to extract values from XML file

I'm currently trying to extract some values from an XML using batch and I have come across xpath.bat

My XML file is formatted in the example below

`<?xml version="1.0"?>
 <data>
     <entry name="Bill" value="hello" type="string"/>
     <entry name="Bob" value="goodbye" type="string"/>
     <entry name="Fred" value="wait" type="string"/>
 <data>

I'd like to find a name in the XML file and report back the value associated. Using xpath.bat I've been able to list all the names but I am unable to retrieve the addtional values.

Alternatively, if anyone is able to extract these values and assign to atch variable using any other method i'd love to see it!

Thanks

Upvotes: 0

Views: 1173

Answers (1)

zx485
zx485

Reputation: 29022

I'd like to find a name in the XML file and report back the value associated.

The shown XML does not have any element values, so it can't return any. It merely has attribute values. So the output seems to be correct.

If you instead want to return the @value attribute value (i.e. for "Bob") the XPath would have to look something like this:

/data/entry[name="Bob"]/@value

Upvotes: 2

Related Questions