PDA

View Full Version : XPath Help


Too_Tall_Crown_Victoria
07-13-2007, 04:15 PM
I am trying to understand how to use xpath and VBP. I have an xml file that will contain the owners of each of our modules. The format is as follows:

<component>
<module name="ProjA" owner="bob@bob.com"/>
<module name="ProjB" owner="tim@tim.com"/>
. . .
</component>

I was using a Step Property action with a value:

[%READ_XML(D:\build\owners.xml,/Component/owner=@module name=%MY_PROJECT%)%]

All I get are errors.

I can get this to work if I use the format:

<component>
<ProjA>
<owner>bob@bob.com</owner>
</ProjA>
<ProjB>
<owner>tim@tim.com</owner>
</ProjB>
. . .
</component>

However I am told that this is not a properly formatted xml file.

Thanks for your help.

kinook
07-16-2007, 08:02 AM
Both a valid XML, although the second one would be difficult to define a schema for.

/Component/owner=@module name=xyz

is not valid XPath. I'm not sure what you're actually trying to retrieve from the XML file?

Here some XPath tutorials:
http://www.google.com/search?hl=en&q=xpath+tutorial
http://en.wikipedia.org/wiki/XPath#External_links

Too_Tall_Crown_Victoria
07-16-2007, 08:57 AM
Here is my new XPath command:

[%READ_XML(D:\build\owners.xml,/Component//module[@name=%MY_PROJECT%)%]

This works but I get a blank macro.

A co-worker of mine is suggesting that the READ_XML macro is not capable of reading and returning just the value of owner. As they cannot find anyway for XPATH to return a specific item in the attribute field.

Do I need to use another tool to get this information?

Too_Tall_Crown_Victoria
07-16-2007, 09:04 AM
I have even tried:

[%READ_XML(D:\build\owners.xml,/Component//module[@name=%MY_PROJECT%/@owner)%]

It does not fail but I get no results. When I need to recieve bob@bob.com for example.

kinook
07-17-2007, 10:32 AM
%READ_XML(D:\build\owners.xml,/component/module[@name='ProjB']/@owner)%