1.0.5 • Published 1 year ago

ngx-xml-to-json v1.0.5

Weekly downloads
294
License
-
Repository
-
Last release
1 year ago

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"
        }
    }
}
1.0.5

1 year ago

1.0.2

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.1

5 years ago