在使用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進行多條件查詢。