0

I am using TinyXPath to enhance an existing test tool so data from a customer XML structure can be fetched and used.

The XML looks like this

<Platform>
  <LinkData>
    <Plan>
      <Label>A</Label>
        <Settings>
           <SomeSetting1>ENABLED</SomeSetting1>
           <SomeSetting2>ENABLED</SomeSetting2>
        </Settings>
    </Plan>
    <Plan>
      <Label>B</Label>
        <Settings>
           <SomeSetting1>ENABLED</SomeSetting1>
           <SomeSetting2>DISABLED</SomeSetting2>
        </Settings>
    </Plan>
  </LinkData>
</Platform>

Given the above structure, which I have no control of, I need to be able to construct XPath expressions for TinyXPath. Put simply TinyXPath needs to return the values in the SomeSetting1/2 fields given when the correct child Label values match (resolve to true), so the test app can use them.

I have tried the following but an struggling with the way is indexed using a child element (normally I would expect use of an attribute. Here is my attempt which does not return a result (e.g. ENABLED/DISABLED) :-

Platform/LinkData/Plan[child::Label='A']/Settings/SomeSetting1/text()
Platform/LinkData/Plan[child::Label='A']/Settings/SomeSetting2/text()
Platform/LinkData/Plan[child::Label='B']/Settings/SomeSetting1/text()
Platform/LinkData/Plan[child::Label='B']/Settings/SomeSetting2/text()

Any further help from TinyXPath gurus would be much appreciated - thanks!

mactwixs
  • 402
  • 1
  • 6
  • 15
  • //Settings/child::node() (add /text() to the end if you just want the Enabled/Disabled text instead of nodes) Or are you trying to get just labels A and B? – JWiley Apr 04 '12 at 13:42
  • The test must return the text values for SomeSetting1&2 firstly for the Plan 'Labelled' A and then for the Plan 'Labelled' B. Thanks. – mactwixs Apr 05 '12 at 12:36

1 Answers1

0

This xpath will return what you're looking for with the given XML:

//Settings/child::node()/text()

This xpath will also add a check for Labels and group by concat |:

//LinkData/Plan[Label/text()='A']/Settings/child::node()/text() | //LinkData/Plan[Label/text()='B']/Settings/child::node()/text()

And this one combines them both inside the label check:

//LinkData/Plan[Label/text()='A' or Label/text()='B']/Settings/child::node()/text()

Hope this helps!

JWiley
  • 3,129
  • 8
  • 41
  • 66
  • Have been unable to get tinyxpath to return any result from the above. Although I can get //LinkData/Plan/Label/text() to work - returns A,B,C etc however adding [] into the query seems to upset it. – mactwixs Apr 13 '12 at 09:01