New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

easy-xml-parser

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-xml-parser

An ultimate tool to parse XMl int JSON format, with awesome result.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Easy XML Parser

XML <-> JSON parser, for easy convert data avoiding unnecesary properties.

Examples


xmlToJson(`
  <root>
    <param arg1="some value"/>
    <param arg1="some value"/>
    <param arg1="some value"/>
    <param2>Text sample</param2>
    <param3 arg="123">Text sample</param3>
    <param4 arg="12" prop="123">
      <inner arg="123"/>
      <inner2 arg="123"/>
      <inner2 arg="123"/>
      <inner2 arg="123"/>
    </param4>
  </root>
`);

// will generate
{
  "root": {
    "param": [
      {
        "arg1": "some value"
      },
      {
        "arg1": "some value"
      },
      {
        "arg1": "some value"
      }
    ],
    "param2": "Text sample",
    "param3": "Text sample",
    "param4": {
      "arg": 12,
      "prop": 123,
      "inner": {
        "arg": 123
      },
      "inner2": [
        {
          "arg": 123
        },
        {
          "arg": 123
        },
        {
          "arg": 123
        }
      ]
    }
  }
}

jsonToXml({
  root: {
    param: [
      {
        arg1: "some value",
      },
      {
        arg1: "some value",
      },
      {
        arg1: "some value",
      },
    ],
    param2: "Text sample",
    param3: "Text sample",
    param4: {
      arg: 12,
      prop: 123,
      inner: {
        arg: 123,
      },
      inner2: [
        {
          arg: 123,
        },
        {
          arg: 123,
        },
        {
          arg: 123,
        },
      ],
    },
  },
});

// will generate
<root param2="Text sample" param3="Text sample">
  <param arg1="some value"/>
  <param arg1="some value"/>
  <param arg1="some value"/>
  <param4 arg="12" prop="123">
    <inner arg="123"/>
    <inner2 arg="123"/>
    <inner2 arg="123"/>
    <inner2 arg="123"/>
  </param4>
</root>

Important Bahavior

// Text content of XML tag will replace all attributes with

xmlToJson(`
  <root>
    <param arg1="some value">Text content</param>
  </root>
`)

// will generate
{
  root: {
    param: "Text content"
  }
}

// next example
xmlToJson(`
  <root>
    <param arg1="some value">Text content</param>
    <param arg1="some value">Text content</param>
    <param arg1="some value">Text content</param>
  </root>
`)

// will generate
{
  "root": {
    "param": [
      "Text content",
      "Text content",
      "Text content"
    ]
  }
}

// Single XMP tag will become as attribute and will replace exisiting one with the same name

Keywords

FAQs

Package last updated on 11 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc