Javascript 获取所有具有相同标签名称的标签值

Javascript get all tag values with the same tag name

下面的 javascript 获取 XML 供稿:

fetch("https://export.arxiv.org/api/query?id_list=1804.10436")
    .then(response => response.text())
    .then(str => new window.DOMParser().parseFromString(str, "text/xml"))

XML 如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <link href="http://arxiv.org/api/query?search_query%3D%26id_list%3D1804.10436%26start%3D0%26max_results%3D10" rel="self" type="application/atom+xml"/>
  <title type="html">ArXiv Query: search_query=&amp;id_list=1804.10436&amp;start=0&amp;max_results=10</title>
  <id>http://arxiv.org/api/nUEsN1vTKh1gSfUw4HiR2ZTFdzs</id>
  <updated>2021-04-15T00:00:00-04:00</updated>
  <opensearch:totalResults xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">1</opensearch:totalResults>
  <opensearch:startIndex xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">0</opensearch:startIndex>
  <opensearch:itemsPerPage xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">10</opensearch:itemsPerPage>
  <entry>
    <id>http://arxiv.org/abs/1804.10436v1</id>
    <updated>2018-04-27T10:57:45Z</updated>
    <published>2018-04-27T10:57:45Z</published>
    <title>Characterizing the highly cited articles: a large-scale bibliometric
  analysis of the top 1% most cited research</title>   
    <author>
      <name>Pablo Dorta-González</name>
    </author>
    <author>
      <name>Yolanda Santana-Jiménez</name>
    </author>
    <arxiv:comment xmlns:arxiv="http://arxiv.org/schemas/atom">23 pages, 6 tables, 2 figures</arxiv:comment>
    <link href="http://arxiv.org/abs/1804.10436v1" rel="alternate" type="text/html"/>
    <link title="pdf" href="http://arxiv.org/pdf/1804.10436v1" rel="related" type="application/pdf"/>
    <arxiv:primary_category xmlns:arxiv="http://arxiv.org/schemas/atom" term="cs.DL" scheme="http://arxiv.org/schemas/atom"/>
    <category term="cs.DL" scheme="http://arxiv.org/schemas/atom"/>
  </entry>
</feed>

如何构造一个逗号分隔的字符串,其中包含 所有 author/name 标签?在上面的 XML 中,我想得到 Pablo Dorta-González, Yolanda Santana-Jiménez

可以使用 DOM 查询来获取解析值。请检查下面的代码片段。

fetch("https://export.arxiv.org/api/query?id_list=1804.10436")
    .then(response => response.text())
    .then(str => new window.DOMParser().parseFromString(str, "text/xml"))
    .then(xml => Array.from(xml.querySelectorAll('author>name')).map(e => e.textContent).join(", "))
    .then(console.log);