在使用XPath多条件查询时,可以通过在查询条件中使用逻辑运算符(and、or)来组合多个条件。下面是一些使用XPath多条件查询的技巧:
$xml = new DOMDocument();
$xml->load('example.xml');
$xpath = new DOMXPath($xml);
$nodes = $xpath->query("//book[author='John Doe' and year='2021']");
$nodes = $xpath->query("//book[author='John Doe' or author='Jane Smith']");
$nodes = $xpath->query("//book[contains(author, 'Doe') and year>'2020']");
$nodes = $xpath->query("//book[(author='John Doe' and year='2021') or (author='Jane Smith' and year='2020')]");
通过这些技巧,可以更灵活地使用XPath进行多条件查询。