【发布时间】:2021-07-03 17:29:50
【问题描述】:
我正在尝试使用以下代码解析来自 NOAA 网站的 xml:
fetch("https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=EDDK&hoursBeforeNow=4",
{mode: 'no-cors'})
.then(response => response.text())
.then(str => (new window.DOMParser()).parseFromString(str, "text/xml"))
.then(data => console.log(data));
但我收到此错误:
This page contains the following errors: error on line 1 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.
对使用 xml 有什么建议吗?
否则,我可以使用结果作为文本然后进行一些正则表达式搜索来避免问题吗?我只需要xml中的第一个data->METAR->raw_text
【问题讨论】:
标签: javascript xml