Filtering an XML file by a string

Hi,

I’m trying to filter an XML file file by a string contained in a node.

I’m using SimpleXML to do it. However, I can only filter by the exact value of a node, I can’t filter by a part of that string. Here i my code:

<all>
<clothes>
<item>The big red shoe</item>
<price>44.99</price>
</clothes>
<clothes>
<item>Small red coat</item>
<price>4.99</price>
</clothes>
</all>

[PHP] $newresult = $result->xpath("//all/clothes/item[.=‘The big red shoe’]/…");
[/PHP]

It works only for the specific string ‘The big red shoe’. I want to instead show all results that contain the word ‘red’.

Any ideas?

Many thanks in advance

It’s been a long time since I used xpath and have no desire to research it right now, but there is a contains() function:

http://www.w3.org/TR/xpath/#function-contains

Sponsor our Newsletter | Privacy Policy | Terms of Service