gpt4 book ai didi

javascript - 在 Javascript 中获取复杂命名空间下的数据

转载 作者:行者123 更新时间:2023-11-28 09:14:40 25 4
gpt4 key购买 nike

我有以下 XML,我需要能够从中提取特定字段:

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<id>Cases</id>
<title type="text">CaseList</title>
<updated>2013-04-04T15:32:56Z</updated>
<author>
<name/>
</author>
<link href="CaseList" rel="self" title="CaseList"/>
<entry>
<id>291</id>
<title type="text">CaseList('291')</title>
<updated>2013-04-04T15:32:56Z</updated>
<category term="S.Cases" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<content type="application/xml">
<m:properties>
<d:case_id>291</d:case_id>
<d:case_title>Global Case</d:case_title>
<d:case_type>Meso</d:case_type>
</m:properties>
</content>
</entry>
<entry>
<id>291</id>
<title type="text">CaseList('292')</title>
<updated>2013-04-04T15:38:56Z</updated>
<category term="S.Cases" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<content type="application/xml">
<m:properties>
<d:case_id>292</d:case_id>
<d:case_title>Global Case 2</d:case_title>
<d:case_type>Meso 2</d:case_type>
</m:properties>
</content>
</entry>
</feed>

我几乎尝试了所有方法,但我觉得我缺少一个核心 XML 概念,它可以帮助我提取 d:case_id 等节点。有没有一种简单的方法可以使用 JavaScript 拉出一个或多个节点?其他命名空间问题不包括另一个命名空间中的命名空间...在这里,我感兴趣的值位于 m:properties 后面。

最佳答案

我用过这个

parentNode.getElementsByTagNameNS("*", "name");

它在 Chrome 和 IE10 浏览器中对我来说运行良好。

请点击以下链接了解详情:

jQuery XML parsing with namespaces

关于javascript - 在 Javascript 中获取复杂命名空间下的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15817891/

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