相关文章推荐
const fxp = require("fast-xml-parser"); const xml2json = fxp.parse(xml); console.log(JSON.stringify(xml2json)); // {"user":[{"name":"ajanuw","age":14},{"name":"alone","age":12}]} const obj = { users: [ {name: 'ajanuw'}, {name: 'alone'} const obj2xml = new fxp.j2xParser().parse(obj) console.log( obj2xml ) // ajanuwalone
const fxp = require("fast-xml-parser");
const obj = {
  xml: {
    _attrs: {
      version: "1.0.1"
    user: [
        _attrs: {
          key: 1
        name: {
          _cdata: "ajanuw",
          _attrs: {
            age: 14,
            height: 166
        _attrs: {
          key: 2
        name: {
          "#text": "alone",
          _attrs: {
            age: 12
const obj2xml = new fxp.j2xParser({
  format: true,
  attrNodeName: "_attrs",
  textNodeName: "#text",
  cdataTagName: "_cdata"
}).parse(obj);
console.log(obj2xml);
<xml version="1.0.1">
  <user key="1">
    <name age="14" height="166">
<![CDATA[ajanuw]]>
    </name>
  </user>
  <user key="2">
    <name age="12">alone</name>
  </user>
 
推荐文章