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

Cannot read property 'getChildren' of undefined

我有一个包含 4000 个孩子的 XML 文件。每个都有几个 children 条目。使用 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个条目,可能缺少条目。但如果我继续重新启动代码,它就会消失。有没有办法检查这个,因为它似乎在遇到时停止处理。

并非所有 children 都出现在每个 child 中。