gpt4 book ai didi

javascript - 解析 XML namespace ?

转载 作者:数据小太阳 更新时间:2023-10-29 01:47:38 24 4
gpt4 key购买 nike

使用 JavaScript/Ajax?

我正在尝试从中提取值:

<yweather:astronomy sunrise="6:34 am"   sunset="8:38 pm"/>

寻找类似的东西:

var response = transport.responseXML.getElementsByTagName("channel");
sunrise = response[0].getElementsByTagName("yweather:astronomy").item(0).Attributes["sunrise"].Value;

但到目前为止没有任何效果。 :'(谢谢。

最佳答案

getElementsByTagName 有一个用于命名空间的特殊版本:getElementsByTagNameNS .

例如:

var response = transport.responseXML.getElementsByTagName("channel");
var sunrise = response[0].getElementsByTagNameNS("[Namespace URI]", "astronomy")[0].getAttribute("sunrise");

...其中 [Namespace URI]yweather 命名空间的 URI。

史蒂夫

关于javascript - 解析 XML namespace ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1083565/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com