xPath 或运算符 2 计算两个以上? [英] xPath or operator two compute more than two?

查看:26
本文介绍了xPath 或运算符 2 计算两个以上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的 xPath,但是我看到 |运算符只计算 2?我怎样才能使它超过两个?我在下面发布了我的代码

This is my xPath, however I see that the | operator computes only 2? How can I make it more than two? I posted my code below

function extractNodeValue($query, $xPath, $attribute = null) {
    $node = $xPath->query("//{$query}")->item(0);
    if (!$node) {
        return null;
    }
    return $attribute ? $node->getAttribute($attribute) : $node->nodeValue;
}


$document = new DOMDocument();
$document->loadHTMLfile(${'html'.$i});
$xPath = new DOMXpath($document);

    $tel = extractNodeValue('//*[@id="eventDetailInfo"]/div[3]/div[4] | //*[@id="eventDetailInfo"]/div[3]/div[3] | //*[@id="eventDetailInfo"]/div[3]/div[5]',$xPath);

推荐答案

当你写2+2+2时,+是一个二元运算符;你的表达意思是(2+2)+2.

When you write 2+2+2, the + is a binary operator; your expression means (2+2)+2.

与 XPath 中的 | 类似,它也是一个二元运算符,但由于结果与操作数的类型相同,因此它以相同的方式与自身组合:$x|$y|$z 表示 ($x|$y)|$z.

Similarly | in XPath is a binary operator, but because the result is of the same type as the operands, it composes with itself in the same way: $x|$y|$z means ($x|$y)|$z.

这篇关于xPath 或运算符 2 计算两个以上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆