【问题标题】:xpath evaluating error in androidandroid中的xpath评估错误
【发布时间】:2010-04-22 04:58:28
【问题描述】:

我在 android 浏览器中运行一个应用程序,其中包含以下代码..

if (typeof XPathResult != "undefined") {
    //use build in xpath support for Safari 3.0
    var xmlDocument = doc;
    if (doc.nodeType != 9) {
        xmlDocument = doc.ownerDocument;
    }
    results = xmlDocument.evaluate( xpathExpr,
                                    doc,
                                    function(prefix) {
                                        return namespaces[prefix] || null;
                                    },
                                    XPathResult.ANY_TYPE,
                                    null );
    var thisResult;
    result = [];
    var len = 0;
    do {
        thisResult = results.iterateNext();
        if (thisResult) {
            result[len] = thisResult;
            len++;
        }
    } while ( thisResult );
}
else {
    try {
        if (doc.selectNodes) {
            result = doc.selectNodes(xpathExpr);
        }
    } catch (ex) {}
}
return result;

但是当我在 Firefox 中运行此应用程序时,请输入 if 语句,一切正常..

但在 android 浏览器中它给出了错误... XPathResult 未定义... 这次控制来到 else 语句,即使在这里它也显示 selectNodes 是未定义的。所以结果为 null 而在 Firefox 中它给出节点列表..

真的需要完成...需要帮助..

谢谢...

【问题讨论】:

  • 您是否在基于 WebKit 的浏览器(如 Chrome 或 Safari)中对此进行了测试?这将比 Firefox 更接近 Android 的浏览器。
  • javascript:alert(navigator.userAgent) 给出什么输出?
  • 在 chrome 中它工作正常...... chrome 和 android 浏览器中的用户代理字符串...... chrome : [Mozila/5.0(Windows;U;Windows NT 5.1,en-US)AppleWebKit/532.5 (KHTML,like Gecko) Chroem/4.1.249.1059 Safari/532.5] android: [Mozila/5.0(Linux;U;Android 2.1;en-US;sdk Build/ERD79)AppleWebKit/530.17 (KHTML,like Gecko)Version/4.0 Mobile Safari/530.17 ] 谢谢大家...需要您的反馈:)
  • 当我遍历整个文档节点时,它没有提供 selectnodes 功能..我使用... for(i in doc)alert(i);它显示了 body、ownerdocument、getfirstchile 等功能......

标签: xml android xpath


【解决方案1】:

Android 浏览器不支持 XPath。 This Android issue 声明它缺少 XmlDocuments,尽管 document.evaluate 对我来说也失败了(只是为了测试,我对 XmlDocuments 感兴趣)

但 Dan 在 7 月 19 日的评论指出,它正在开发 3.0 Where is XPathEvaluator in android web browser?

很遗憾,3.x 仅适用于平板电脑,因此我们将不得不等待很长时间,直到 IceCream 发布并适用于手机。

这是浏览器撒谎的另一种情况,正如this message(没有回复)中所述,浏览器声称实现了 XPath 3.0,但事实是它不可用,所以返回 true 是一个谎言。

【讨论】:

    猜你喜欢
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-07
    • 1970-01-01
    • 2013-11-04
    • 2010-11-03
    • 1970-01-01
    相关资源
    最近更新 更多