1

i would like to select element, that has few childs with specific values. Here is example of xml: `

<events>
  <event>
    <startDateTime>2012-12-0128090</startDateTime>
    <homeTeam>
      <name>TEST123</name>
    </homeTeam>
  </event>
</events>`

Result i want is event, that contains startDateTime with value 2012-12-01 and contains TEST value of homeTeam/Name.

I am trying like this:

//events/event[startDateTime[contains(.,'2012-12-01')] and homeTeam/name[contains(.,'TEST')]]');

This returns me also events with starDateTime different from specified.

Thanks in advance.

0

1 Answer 1

3

I tweaked your XML and XPath slightly

<events>
    <event>
        <startDateTime>2012-12-0128090</startDateTime>
        <homeTeam>
            <name>TEST123</name>
        </homeTeam>
    </event>
    <event>
        <startDateTime>*2013-12-0128090*</startDateTime>
        <homeTeam>
            <name>TEST123</name>
        </homeTeam>
    </event>
</events>

I then used the following XPath to access the second node:

//events/event[(startDateTime[contains(.,'2013-12-01')]) and (homeTeam/name[contains(.,'TEST')])]

I also tested it with different name values, and it seems to work fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.