lemonade

XPath query with PHP

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Here's the XML code I'm working with: <inventory> <drink> <lemonade supplier="mother" id="1"> <price>$2.50</price> <amount>20</amount> </lemonade> <lemonade supplier="mike" id="4"> <price>$3.00</price> <amount>20</amount> </lemonade> <pop supplier="store" id="2"> <price>$1.50</price> <amount>10</amount> </pop> </drink> </inventory> Then I wrote a simple code to practice working with XPath: <?php $xmldoc = new DOMDocument(); $xmldoc->load('sample.xml'); $xpathvar = new Domxpath($xmldoc); $queryResult = $xpathvar->query('//lemonade/price');