I have the folowing code:
$xml = simplexml_load_file($url);
$query = '/root/parent[Model="Corolla"]';
//RUN QUERY ON XML
$xQuery = $xml->xpath($query);
And here is the XML file:
<root>
<parent>
<Model>Corolla A/C</Model>
</parent>
</root>
This code works good if I’m searching for the exact string “Corolla”. The problem I’m having is that some of the values are similar to “Corolla A/C good condition”
Is there a way I can query the XML file for any Model element that contains the word Corolla rather then the exact string Corolla?
EDIT: I added an example of my XML help clarify.
In this particular case I would suggest the
starts-withfunction rather thancontains(given the assumption all your models begin with the word “Corolla”):EDIT
Based on your edit, you would have to change the query to:
You may also have a look at the Zvon XSLT Tutorial. It’s a very nice read.