I wrote a Xpath query to look for an element with a nodeValue that contains a string.
/campaigns/campaign[contains("7218322441485795", creative_id)]
However, the XML I’m querying has multiple <creative_id> elements;
<campaigns>
<campaign>
<creative_id>41485795</creative_id>
<creative_id>41485759</creative_id>
<creative_id>41485694</creative_id>
<resources>
....
The problem is that the query only evaluates the first creative_id element and not second & third.
How do I write the XPath query to not be limited to the first creative_id element?
The XPath
containsfunction returnstruewhen the string value of the second argument is found in the first argument. Your ordering seems suspicious. You’re currently looking for the string value ofcreative_idin the given string, not the value of that string increative_id.Assuming that the argument ordering is correct, the following expression returns a
campaignelement if any of itscreative_idchildren match a portion of the provided string: