无法读取未定义的属性'getChildren'



我有一个包含4000个孩子的XML文件。每个条目中都有几个子条目。使用P5.js。我使用loadXML加载文件,完成后,我运行这段代码,首先检查是否存在xmlWx.

airportData = xmlWx.getChild('data').getChildren('METAR');
stations = xmlWx.getChild('data').getChildren('station_id');
latitudes = xmlWx.getChild('data').getChildren('latitude');
longitudes = xmlWx.getChild('data').getChildren('longitude');

我间歇性地得到

Cannot read property 'getChildren' of undefined

下面是一个数据示例:

<METAR>
<raw_text>KIFP 091948Z 22004KT 10SM BKN080 BKN100 18/M04 A2994</raw_text>
<station_id>KIFP</station_id>
<observation_time>2021-02-09T19:48:00Z</observation_time>
<latitude>35.15</latitude>
<longitude>-114.57</longitude>
</METAR>

有4000个条目,可能会有丢失的条目。但是如果我重新启动代码它就消失了。是否有办法检查这个,因为它似乎在遇到时停止处理。

不是所有的孩子都出现在每个孩子身上。

最新更新