ngx-xml-to-json

ngx-xml-to-json JS library on npm Download ngx-xml-to-json JS library

An Angular 14 library to convert xml to json.

Version 1.0.5 Vulnerabilities 0
ngx-xml-to-json has no homepage
ngx-xml-to-json JS library on GitHub
ngx-xml-to-json JS library on npm
Download ngx-xml-to-json JS library
Keywords
jsonxmlxml to jsonangularangular 14ngxngx-xml-to-jsonxml2json
INSTALL
Type:
No default JS file set by the package author so the URL is guessed. You can always browse all package files to use another one.

NgxXmlToJson

An Angular 14 library to convert xml to json.

Installation

npm install ngx-xml-to-json --save

Example

import { Component } from '@angular/core';
import { NgxXmlToJsonService } from 'ngx-xml-to-json';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
   xml= `<contact-info><address category = "Profile" type = "Address" ><name color='white'><![CDATA[ Welcome to XML Converter]]>XML Parser</name><company>OpenSource</company><phone>(011) 123-4567</phone></address><address/><personal category = "Name"> XML Parser</personal></contact-info>`;
  constructor(private ngxXmlToJsonService: NgxXmlToJsonService) {
    const options = { // set up the default options 
      textKey: 'text', // tag name for text nodes
      attrKey: 'attr', // tag for attr groups
      cdataKey: 'cdata', // tag for cdata nodes (ignored if mergeCDATA is true)
    };
    const jsonObj = this.ngxXmlToJsonService.xmlToJson(this.xml, options)
  }
}

Result

{
    "contact-info": {
        "address":[
            {
                "attr" : {
                    "category": "Profile",
                    "type": "address"
                },
                "company": {
                    "text": "OpenSource"
                },
                "name": {
                    "attr" : {
                        "color": "white"
                    },
                    "cData": "Welcome to XML Converter",
                    "text": "XML Parser"
                },
                "phone": {
                    "text": "(011) 123-4567"
                }
            }
        ],
        "personal": {
            "attr" : {
                "category": "Name"
            },
            "text": "XML Parser"
        }
    }
}