Quasar 2.6.0 中的 xml2js 遇到问题

问题描述 投票:0回答:1

我需要以下代码才能在 Quasar 2.6.0 应用程序中运行。

async fetchAbstracts() {
  try {
    const url = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id=33888705,18340043,19033662,20978265,23204432,23275034,23892238&retmode=xml';
    const response = await axios.get(url);
    const xmlData = response.data;
    const parser = new xml2js.Parser({ explicitArray: false, ignoreAttrs: true });

    parser.parseString(xmlData, (err, result) => {
      if (err) {
        throw err;
      }
      
      // Assuming the structure of the XML is known and consistent
      // Navigate to the abstract texts. This path might need adjustments
      const articles = result.PubmedArticleSet.PubmedArticle || [];
      articles.forEach(article => {
        const abstractText = article.MedlineCitation.Article.Abstract.AbstractText;
        
        // AbstractText can be an array if there are multiple paragraphs or sections
        if (Array.isArray(abstractText)) {
          abstractText.forEach((text, index) => {
            console.log(`Abstract Section ${index + 1}: ${text}`);
          });
        } else {
          console.log(`Abstract: ${abstractText}`);
        }
      });
    });
  } catch (error) {
    console.error('Error fetching or parsing the XML:', error);
  }
}

我有

import axios from "axios";
import xml2js from "xml2js";

在我的脚本文件中,但是当我到达时

 const parser = new xml2js.Parser({ explicitArray: false, ignoreAttrs: true });

它抛出以下错误:

Error fetching or parsing the XML: TypeError: this.removeAllListeners is not a function
vue.js quasar xml2js
1个回答
0
投票

解决方案来自同一问题的 GitHub 问题。许多人报告安装 events 软件包后问题得到解决。

npm install events

yarn add events
© www.soinside.com 2019 - 2024. All rights reserved.