Javascript 解析XML名称空间?

Javascript 解析XML名称空间?,javascript,xml,ajax,namespaces,Javascript,Xml,Ajax,Namespaces,使用JavaScript/Ajax 我试图从以下内容中提取值: <yweather:astronomy sunrise="6:34 am" sunset="8:38 pm"/> 但到目前为止一切都不起作用( 谢谢。有一个特殊版本的getElementsByTagName用于名称空间: 例如: var response = transport.responseXML.getElementsByTagName("channel"); var sunrise = response[

使用JavaScript/Ajax

我试图从以下内容中提取值:

<yweather:astronomy sunrise="6:34 am"   sunset="8:38 pm"/>
但到目前为止一切都不起作用(
谢谢。

有一个特殊版本的
getElementsByTagName
用于名称空间:

例如:

var response = transport.responseXML.getElementsByTagName("channel");
var sunrise = response[0].getElementsByTagNameNS("[Namespace URI]", "astronomy")[0].getAttribute("sunrise");
…其中
[Namespace URI]
yweather
命名空间的URI


Steve

@annakata:出于兴趣,你怎么能在IE中实现呢?我想你可以在IE中使用getElementsByTagName(“yweather:astronomy”)。此外,Google feeds API有一个跨浏览器实现。也许你可以使用它,或者类似的东西:在MSXML中,你可以设置“SelectionNamespaces”属性,然后将非标准的“selectNodes”(或“selectSingleNode”)方法与XPath选择器一起使用。例如,请参阅。@NickFitz:啊,我明白了。谢谢!您可能需要转义冒号“yweather\\:astronomy”
var response = transport.responseXML.getElementsByTagName("channel");
var sunrise = response[0].getElementsByTagNameNS("[Namespace URI]", "astronomy")[0].getAttribute("sunrise");