The code below attempts to find all XML "name" elements that start with 'desk' (using the starts-with method) and trim any leading white space in the XML elements (using the normalize-space and concat methods). However the code isn't retrieving any data. And advice? Thanks in advance!
$xmldoc = simplexml_load_file("products.xml");
$query = $xmldoc->xpath("/products/product[starts-with(normalize-space(concat(' ',name, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz')), 'desk')]");
foreach($query as $Products) {
echo $Products->name . " ";
echo $Products->price . "<br>";
}
<products>
<product type="Electronics">
<name> Desktop</name>
<price>499.99</price>
<store>Best Buy</store>
</product>
</products>