使用PHP和XPath,我试图使用XPath的start-with函数从下面的XML文件中的“name”元素中检索数据。下面的代码不会检索任何内容。任何人都可以建议吗?谢谢!
$xmldoc = simplexml_load_file("products.xml");
$query = $xmldoc->xpath('/products/product[starts-with(name, "Desk")]');
foreach($query as $Products) {
echo $Products->name . " ";
echo $Products->price . "<br>";
}
这是XML文件(名为product.xml):
<products>
<product type="Electronics">
<name>Desktop</name>
<price>499.99</price>
<store>Best Buy</store>
</product>
<product type="Hardware">
<name>Hand Saw</name>
<price>99.99</price>
<store>Lowes</store>
</product>
</products>