Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Firefox中使用XPath名称空间_Javascript_Xml_Firefox_Xpath - Fatal编程技术网

Javascript 在Firefox中使用XPath名称空间

Javascript 在Firefox中使用XPath名称空间,javascript,xml,firefox,xpath,Javascript,Xml,Firefox,Xpath,我试图在Javascript中解析xml文件,同时忽略xml文件的名称空间。我不认为xml文件的名称空间将来会发生变化,不过如果代码能够正常工作,即使名称空间发生了任意变化,我会更高兴。我试图跟随,但没有成功 为了使第二个版本成功地找到xml节点,我需要更改什么?下面是我的代码,它不能按预期工作。具体来说,对Components.utils.reportError的第三次调用输出null firefox扩展中的Javascript: Components.utils.reportError("X

我试图在Javascript中解析xml文件,同时忽略xml文件的名称空间。我不认为xml文件的名称空间将来会发生变化,不过如果代码能够正常工作,即使名称空间发生了任意变化,我会更高兴。我试图跟随,但没有成功

为了使第二个版本成功地找到xml节点,我需要更改什么?下面是我的代码,它不能按预期工作。具体来说,对Components.utils.reportError的第三次调用输出null

firefox扩展中的Javascript:

Components.utils.reportError("XML A: " + docky.documentElement);
var testxpath = '//' + docky.documentElement.tagName + ":entry";
Components.utils.reportError("Test XPath: " + testxpath);
Components.utils.reportError(docky.evaluate(testxpath, docky, 
    function(){return 'http://tempuri.org/';}, 
    XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue);
Components.utils.reportError("XML A: " + docky.documentElement);
var testxpath = '//' + docky.documentElement.tagName;
Components.utils.reportError("Test XPath: " + testxpath);
Components.utils.reportError(docky.evaluate(testxpath, docky, null, 
    XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue);
XML文件:

<OutputBlob xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns="http://tempuri.org/">
    <rnd>
        <double>0.23500252665719135</double>
        <double>0.82559380951597994</double>
        <double>0.33431208335529644</double>
        <double>0.91389494431852125</double>
    </rnd>
</OutputBlob>
<OutputBlob xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
    <rnd>
        <double>0.23500252665719135</double>
        <double>0.82559380951597994</double>
        <double>0.33431208335529644</double>
        <double>0.91389494431852125</double>
    </rnd>
</OutputBlob>
下面我的代码的变体,即不涉及名称空间的地方,工作正常。也就是说,对Components.utils.reportError的第三次调用不会输出null

firefox扩展中的Javascript:

Components.utils.reportError("XML A: " + docky.documentElement);
var testxpath = '//' + docky.documentElement.tagName + ":entry";
Components.utils.reportError("Test XPath: " + testxpath);
Components.utils.reportError(docky.evaluate(testxpath, docky, 
    function(){return 'http://tempuri.org/';}, 
    XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue);
Components.utils.reportError("XML A: " + docky.documentElement);
var testxpath = '//' + docky.documentElement.tagName;
Components.utils.reportError("Test XPath: " + testxpath);
Components.utils.reportError(docky.evaluate(testxpath, docky, null, 
    XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue);
XML文件:

<OutputBlob xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns="http://tempuri.org/">
    <rnd>
        <double>0.23500252665719135</double>
        <double>0.82559380951597994</double>
        <double>0.33431208335529644</double>
        <double>0.91389494431852125</double>
    </rnd>
</OutputBlob>
<OutputBlob xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
    <rnd>
        <double>0.23500252665719135</double>
        <double>0.82559380951597994</double>
        <double>0.33431208335529644</double>
        <double>0.91389494431852125</double>
    </rnd>
</OutputBlob>
修复:替换

var testxpath = '//' + docky.documentElement.tagName + ":entry";