标签: xml2js

从Axios响应中解析XML,推送到Vue数据阵列

在我的Vue应用程序中,我获得了一个带有Axios的XML文件,并使用parseString将XML解析为JSON.然后我需要传递result给Vue数据(this.events).我的控制台日志将解析后的XML显示为Json,但我无法在此函数中推送到Vue数据.

var parseString = require('xml2js').parseString;

axios.get(`http://url.to/events.xml`)
  .then(response => {
    parseString(response.data, function (err, result) {
      console.log(result); // returns a json array
      this.events = result // nothing happens
    });        
  })
}
Run Code Online (Sandbox Code Playgroud)

如何在Vue中将我的JSON数组存储到this.data?

xml vue.js axios xml2js

8
推荐指数
2
解决办法
1万
查看次数

xml2js 容易受到原型污染

xml2js <=0.4.23 严重性:高 xml2js 容易受到原型污染 - https://github.com/advisories/GHSA-776f-qx25-q3cc 没有可用的修复 node_modules/xml2js aws-sdk * 取决于 xml2js node_modules 的易受攻击版本/aws-sdk

2个高危漏洞

将 aws-sdk npm 软件包升级到最新版本。但脆弱性仍然存在。

python security aws-sdk xml2js

8
推荐指数
1
解决办法
5162
查看次数

从Angular 5更新到6后,我不断收到错误:无法解析xml2js中的计时器

就像标题所说,我继续得到这个奇怪的错误.我也尝试使用npm uninstall xml2js卸载它,但直到现在还没有任何工作.

在此输入图像描述

npm xml2js angular angular5 angular6

7
推荐指数
1
解决办法
5469
查看次数

解析xml的字符实体无效

我试图解析一串xml,我收到一个错误

[Error: Invalid character entity
Line: 0
Column: 837
Char:  ]
Run Code Online (Sandbox Code Playgroud)

xml不喜欢括号吗?我是否需要用\\]等替换所有括号.谢谢

node.js xml2js

6
推荐指数
2
解决办法
4994
查看次数

使用 xml2js parseString 返回值

xml = `
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soap:Body>
      <GetCurrentRoomStatusGraphResponse xmlns="www.example.com">

         ...

         </GetCurrentRoomStatusGraphResult>
      </GetCurrentRoomStatusGraphResponse>
   </soap:Body>
</soap:Envelope>
`


var parseString = require('xml2js').parseString;
parseString(xml, function (err, result) {
    console.dir(result);
});
Run Code Online (Sandbox Code Playgroud)

我想要另一个函数使用这个值,如何返回这样的值?

parseString(xml, function (err, result) {
  return result
});
Run Code Online (Sandbox Code Playgroud)

javascript xml json node.js xml2js

6
推荐指数
1
解决办法
1万
查看次数

如何从ES6中的解析器中获取xml2js结果?

我正在Node中构建一个服务器,它将搜索文件夹以查看是否存在XML文件(glob),如果存在,则将(fs)中的文件作为JSON对象(xml2js)读取并最终将其存储在数据库中某处.我想要将解析器的结果输出到另一个变量中,以便我可以对数据执行其他操作.从我所知道的情况来看,有些东西是同步运行的,但是我无法弄清楚如何阻止它并让我等到它完成继续前进.

我将我的功能分离到app.js的其他控制器:

app.controller.js

const fs = require('fs-extra');
const glob = require('glob');
const xml2js = require('xml2js');

exports.requests = {};

exports.checkFileDrop = async () => {
  console.log('Checking for xml in filedrop...');
  // this is the only place await works...
  await glob('./filedrop/ALLREQUESTS-*.xml', (err, files) => {
    var parser = new xml2js.Parser();
    // this is looking for a specific file now, which I'll address later once I can figure out this issue
    fs.readFile('./filedrop/ALLREQUESTS-20170707.xml', 'utf16le', function (err, data) { 
      if (err) {
        console.log('ERROR: ', err); …
Run Code Online (Sandbox Code Playgroud)

javascript fs node.js ecmascript-6 xml2js

5
推荐指数
1
解决办法
3915
查看次数

使用 Typescript 和 xml2js 解析 XML

我正在尝试使用 Express 并解析 XML 正文。我将 bodyparser 用于文本,但无法让 xml2js 将我的 XML 解析为可用格式。

import * as xml2js from 'xml2js';
try {
    const XML:string = '<Pan>0000000000000702203</Pan>';

    xml2js.parseString(XML, {trim: true}, function (err, result) {
        if(err) console.log(err);
        console.log(result); 
    });
} catch (e) {
    console.log(e);
}
Run Code Online (Sandbox Code Playgroud)

要么不起作用:

try {
    xml2js.parseString(XML, {trim: true}, (err, result) => {
        if(err) console.log(err);
        console.log(result); 
    });
} catch (e) {
    console.log(e);
}
Run Code Online (Sandbox Code Playgroud)

在 VSCode 调试器中运行它时,代码会立即跳过该函数并且不处理 xml2js.parseString()。错误和结果永远不会得到值。

我也尝试过使用 Parser() 类:

const p:xml2js.Parser = new xml2js.Parser();
p.parseString(XML, (err:{}, result:{}) => {
    if(err) console.log(err);
    console.log(result); …
Run Code Online (Sandbox Code Playgroud)

xml typescript xml2js

5
推荐指数
1
解决办法
5226
查看次数

如何使用Node xml2js模块转义字符?

我有一个带有&的xml文档,因此出现错误

   [Error: Invalid character in entity name
   Line: 155
   Column: 63
   Char:  ]
Run Code Online (Sandbox Code Playgroud)

我编写了一个函数来转义非法的xml字符:

const escapeIllegalCharacters = (xml) => {
  xml = xml 
    .replace(/&/g,'&amp;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&apos;')
    .replace(/>/g, '&gt;')
    .replace(/</g, '&lt;');
  return (xml);
}
Run Code Online (Sandbox Code Playgroud)

并将其放入valueProcessor中:

return parse.parseString(xml, {valueProcessors: [escapeIllegalCharacters]});
Run Code Online (Sandbox Code Playgroud)

但是我仍然遇到同样的错误。这是使用xml2js模块转义字符的错误方法吗?

xml node.js xml-parsing xml2js

4
推荐指数
1
解决办法
1525
查看次数

如何使用angular-cli和webpack在angular2应用程序中导入xml2js

对于使用angular2的应用程序(来自带有webpack的angular-cli),我需要从soap web服务中使用xml中的一些数据.我使用的angular-cli本身提供了用于将xml解析为json的库xml2js但是当我尝试使用以下语法在我的组件中使用此库:

import {Parser} from 'xml2js';
Run Code Online (Sandbox Code Playgroud)

我收到了消息:

Cannot find module 'xml2js'.)
Run Code Online (Sandbox Code Playgroud)

但是,此库实际上安装在node_modules文件中.

我到处搜索,但我只找到了一些system.js配置的解决方案.

有没有人知道如何使用webpack在angular2中使用这个库?

xml angular-cli xml2js angular

4
推荐指数
1
解决办法
5023
查看次数

xml2js - 将xml标记值转换为jsons数组

我使用以下代码将xml转换为json: -

var parseString = require('xml2js').parseString;

var xml = "<root><param_name>Hello</param_name><param_entry> xml2js!  </param_entry> </root>";

parseString(xml, {trim: true},function(err,result){
console.dir(JSON.stringify(result));
});
Run Code Online (Sandbox Code Playgroud)

它返回以下结果 -

{  
   "root":{  
  "param_name":[  
     "Hello"
  ],
  "param_entry":[  
     " xml2js!"
  ]
     }
   }
Run Code Online (Sandbox Code Playgroud)

它返回作为对象集合的值,即"param_name":[
"Hello"].

但我希望它是一个简单的键和价值形式.这是我的结果JSON应该看起来像 -

{  
   "root":{  
      "param_name":  
         "Hello"
      ,
      "param_entry":
         " xml2js!"

   }
}
Run Code Online (Sandbox Code Playgroud)

这里出了什么问题?

xml json xml2js

2
推荐指数
1
解决办法
3063
查看次数

使用 xml2js 解析的问题

我有一个 xml,其中标记名称包含冒号 (:) 它看起来像这样:

<samlp:Response>
data
</samlp:Response>
Run Code Online (Sandbox Code Playgroud)

我正在使用以下代码将此 xml 解析为 json,但无法使用它,因为标记名称包含冒号。

var xml2js = require('xml2js');
var parser = new xml2js.Parser();
var fs = require('fs');

    fs.readFile(
  filePath,
  function(err,data){
    if(!err){
      parser.parseString(data, function (err, result) {
        //Getting a linter warning/error at this point
        console.log(result.samlp:Response);
      });
    }else{
      callback('error while parsing assertion'+err);
    }
  }
);

};
Run Code Online (Sandbox Code Playgroud)

错误:

events.js:161
      throw er; // Unhandled 'error' event
      ^

TypeError: Cannot read property 'Response' of undefined
Run Code Online (Sandbox Code Playgroud)

如何在不更改 xml 内容的情况下成功解析此 XML?

在此处输入图片说明

javascript node.js xml2js

2
推荐指数
1
解决办法
3057
查看次数

使用 xml2js 在 Angular 6 中未定义 parseString

到目前为止,我无法使用 Angular 6 让 xml2js 代码正常工作。我有一个 service.ts 返回 xml,但是当调用 xml2js.parseString 转换为 json 时,我始终收到未定义的错误。

“core.js:1673错误TypeError:无法读取未定义的属性'parseString'”

服务.ts

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, of } from 'rxjs';
import { map, filter, catchError, mergeMap } from 'rxjs/operators';
import { HttpHeaders } from '@angular/common/http';

export interface Zid {
  zpid: number;
}
const httpOptions = {
  headers: new HttpHeaders({
    'Content-Type': 'application/x-www-form-urlencoded',
  }),
  responseType: 'text' as 'text'
};    

@Injectable({
  providedIn: 'root'
})

export class CdataServiceService {

  constructor(private …
Run Code Online (Sandbox Code Playgroud)

xml json typescript xml2js angular

2
推荐指数
1
解决办法
8509
查看次数