php xpath方法查询xml

<!--markdown-->假定我们有个123.xml文件,代码如下:

$dom = new DOMDocument('1.0','utf-8');
$dom->load('123.xml');
$xpath = new DOMXPath($dom);
$sql = '/test/str[name="'.$str.'"]';
$wordList = $xpath->query($sql);
if($wordList->length === 0){
echo "not found";
提交