通过selectNode在Safari中读取XML [英] Reading XML in Safari through selectNode

查看:69
本文介绍了通过selectNode在Safari中读取XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各位大家好,


在我的应用程序中,我有大量使用远程XML文件的脚本

填写表格并评估内容;在这些脚本中,我总是使用

方法SelectNode(有一些解决方法,也可以在

Mozilla中正常工作)。

我''我刚刚发现这种方法在Safari浏览器中不起作用,因此我的应用程序无法通过此浏览器使用。

任何人都可以为我提供任何解决方案或解决方法在Safari中读取XML

文件,而不是重写我的所有脚本?


谢谢大家:)

Hello everybody,

In my applications I''ve a ton of scripts that use remote XML file to
fill forms and evaluate contents; In these scripts I always use the
method SelectNode (that, with some workaround, works fine also in
Mozilla).
I''ve just found out that this method doesnt work in Safari browser,
therefore my applications are not usable by this browser.
Can anyone provide me any solution or workaround to be able to read XML
files in Safari wihout rewriting all of my scripts??

Thanks everyone :)

推荐答案

J_Zanetti写道:
J_Zanetti wrote:

在我的应用程序中,我有大量使用远程XML文件的脚本

填写表格并评估内容;在这些脚本中,我总是使用

方法SelectNode(通过一些解决方法,也可以在

Mozilla中正常工作)。
In my applications I''ve a ton of scripts that use remote XML file to
fill forms and evaluate contents; In these scripts I always use the
method SelectNode (that, with some workaround, works fine also in
Mozilla).



使用MSXML和Mozilla的IE都没有在XML DOM对象上公开的任何名为SelectNode

的方法。

MSXML提供了两种方法,一种叫做selectSingleNode,另一种是名为selectNodes的
。你在使用其中一种吗?

Neither IE using MSXML nor Mozilla have any method called SelectNode
exposed on XML DOM objects.
MSXML provides two methods, one called selectSingleNode, the other
called selectNodes. Are you using one of these?


我刚刚发现这种方法在Safari浏览器中不起作用,

因此我的应用程序这个浏览器无法使用。

任何人都可以为我提供任何解决方案或解决方法,以便能够在Safari中读取XML

文件而无需重写我的所有脚本?
I''ve just found out that this method doesnt work in Safari browser,
therefore my applications are not usable by this browser.
Can anyone provide me any solution or workaround to be able to read XML
files in Safari wihout rewriting all of my scripts??



我认为Safari到目前为止还没有XPath支持因此如果你真的使用

XPath表达式作为该函数的参数那么你需要写更多代码
。对于其他简单的任务,您可以使用

getElementsByTagName,例如你可以替换

xmlDoc.selectNodes(''// element-name'')

with

xmlDoc.getElementsByTagName(''element-姓名'')

-


Martin Honnen
http://JavaScript.FAQTs.com/




Martin Honnen ha scritto :

Martin Honnen ha scritto:

MSXML提供了两种方法,一种叫做selectSingleNode,另一种是名为selectNodes的
。你在用这些吗?
MSXML provides two methods, one called selectSingleNode, the other
called selectNodes. Are you using one of these?



感谢您回答Martin!

是的,我正在使用selectNodes。当然它适用于IE,并且只有在我添加一些重新定义此方法工作的代码时,才能在Mozilla中使用
;确切地说是
,我在我的脚本开头添加了这段代码


if(document.implementation.hasFeature(" XPath"," 3.0) ))

{

//原型化XMLDocument

XMLDocument.prototype.selectNodes = function(cXPathString,xNode)

{

if(!xNode){xNode = this; }

var oNSResolver = this.createNSResolver(this.documentElement)

var aItems = this.evaluate(cXPathString,xNode,oNSResolver,

XPathResult .ORDERED_NODE_SNAPSHOT_TYPE,null)

var aResult = [];

for(var i = 0; i< aItems.snapshotLength; i ++)

{

aResult [i] = aItems.snapshotItem(i);

}

返回aResult;

}

//原型元素

Element.prototype.selectNodes = function(cXPathString)

{

if (this.ownerDocument.selectNodes)

{

返回this.ownerDocument.selectNodes(cXPathString,this);

}

else {throw"仅限XML Elements';}}

}

}


这在Safari下不起作用,因为那里不支持Xpath;因此

我应该为Safari编写类似的内容吗?老实说,我不会知道

从哪里开始......

Thanks for answering Martin!
Yes, Im using selectNodes. Of course it works on IE, and in Mozilla
only if i add some code that redefine the working of this method; to be
precise, i add this code at the beginning of my script

if( document.implementation.hasFeature("XPath", "3.0") )
{
// prototying the XMLDocument
XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
{
if( !xNode ) { xNode = this; }
var oNSResolver = this.createNSResolver(this.documentElement)
var aItems = this.evaluate(cXPathString, xNode, oNSResolver,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
var aResult = [];
for( var i = 0; i < aItems.snapshotLength; i++)
{
aResult[i] = aItems.snapshotItem(i);
}
return aResult;
}
// prototying the Element
Element.prototype.selectNodes = function(cXPathString)
{
if(this.ownerDocument.selectNodes)
{
return this.ownerDocument.selectNodes(cXPathString, this);
}
else{throw "For XML Elements Only";}
}
}

This doesnt work under Safari, since Xpath is not supported there; thus
should i write something similar for Safari? Honestly, i wouldnt know
where to start from...


我认为Safari到目前为止还没有XPath支持你真的使用

XPath表达式作为该函数的参数然后你需要写更多的代码。对于其他简单的任务,您可以使用

getElementsByTagName,例如你可以替换
I don''t think Safari has XPath support so far thus if you really use
XPath expressions as arguments to that functions then you need to write
more code. For other simple tasks you might get away with using
getElementsByTagName e.g. you can replace



是的,我使用xpath表达式作为selectNodes方法的参数

:(

所以如果我做得好,有两种选择:用

getElementsByTagName重新编写我的脚本或重新定义selectNodes。你认为哪种方式最好?
是最好的?

Yes, I use xpath expressions as parameters for the selectNodes method
:(
So If i got it well, there are two options: rewriting my scripts with
getElementsByTagName or redefining selectNodes. Which way do you think
is the best one?




Martin Honnen ha scritto:

Martin Honnen ha scritto:

MSXML提供两种方法,一种名为selectSingleNode,另一个名为selectNodes的
。您使用的是其中之一吗?
MSXML provides two methods, one called selectSingleNode, the other
called selectNodes. Are you using one of these?



感谢您回答Martin!

是的,我正在使用selectNodes。当然它适用于IE,并且在Mozilla

只有当我添加一些重新定义此方法工作的代码时才能使用

确切地说,我在我的脚本开头添加了这段代码


if(document.implementation.hasFeature(" XPath"," 3.0"))

{

//原型XMLDocument

XMLDocument.prototype.selectNodes = function(cXPathString,xNode)

{

if(!xNode){xNode = this; }

var oNSResolver = this.createNSResolver(this.documentElement)

var aItems = this.evaluate(cXPathString,xNode,oNSResolver,

XPathResult .ORDERED_NODE_SNAPSHOT_TYPE,null)

var aResult = [];

for(var i = 0; i< aItems.snapshotLength; i ++)

{

aResult [i] = aItems.snapshotItem(i);

}

返回aResult;

}

//原型元素

Element.prototype.selectNodes = function(cXPathString)

{

if (this.ownerDocument.selectNodes)

{

返回this.ownerDocument.selectNodes(cXPathString,this);

}

else {throw"仅限XML Elements';}}

}

}


这在Safari下不起作用,因为那里不支持Xpath;因此

我应该为Safari编写类似的内容吗?老实说,我不会知道

从哪里开始......

Thanks for answering Martin!
Yes, Im using selectNodes. Of course it works on IE, and in Mozilla
only if i add some code that redefine the working of this method; to be
precise, i add this code at the beginning of my script

if( document.implementation.hasFeature("XPath", "3.0") )
{
// prototying the XMLDocument
XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
{
if( !xNode ) { xNode = this; }
var oNSResolver = this.createNSResolver(this.documentElement)
var aItems = this.evaluate(cXPathString, xNode, oNSResolver,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
var aResult = [];
for( var i = 0; i < aItems.snapshotLength; i++)
{
aResult[i] = aItems.snapshotItem(i);
}
return aResult;
}
// prototying the Element
Element.prototype.selectNodes = function(cXPathString)
{
if(this.ownerDocument.selectNodes)
{
return this.ownerDocument.selectNodes(cXPathString, this);
}
else{throw "For XML Elements Only";}
}
}

This doesnt work under Safari, since Xpath is not supported there; thus
should i write something similar for Safari? Honestly, i wouldnt know
where to start from...


我认为Safari到目前为止还没有XPath支持你真的使用

XPath表达式作为该函数的参数然后你需要写更多的代码。对于其他简单的任务,您可以使用

getElementsByTagName,例如你可以替换
I don''t think Safari has XPath support so far thus if you really use
XPath expressions as arguments to that functions then you need to write
more code. For other simple tasks you might get away with using
getElementsByTagName e.g. you can replace



是的,我使用xpath表达式作为selectNodes方法的参数

:(

所以如果我做得好,有两种选择:用

getElementsByTagName重新编写我的脚本或重新定义selectNodes。你认为哪种方式最好?
是最好的?

Yes, I use xpath expressions as parameters for the selectNodes method
:(
So If i got it well, there are two options: rewriting my scripts with
getElementsByTagName or redefining selectNodes. Which way do you think
is the best one?


这篇关于通过selectNode在Safari中读取XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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