XML data parsing in angular 2

10,761

By today, the suggested code in other answer (which suggests node-xml2js) didn´t work. Instead of:

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

I used:

import { parseString } from 'xml2js';

The remaining part was ok. Angular-cli used.

Share:
10,761
biff
Author by

biff

Coder By Passion

Updated on June 04, 2022

Comments

  • biff
    biff almost 2 years

    Im new to angularjs2 and typescript,in my project i have a string variable comtaining xml as string, i need to process the string and access the data in the string according to node in the XML.Im having tough time by googling.Please help me out.

    <groupDirectory>
    <directoryDetails>
     <userId>extn5001</userId>
     <firstName>Park</firstName>
     <lastName>1</lastName>
     <groupId>communications</groupId>
     <extension>5001</extension>
    </directoryDetails>
    <directoryDetails>
     <userId>Yealinkt27ptest</userId>
     <firstName>Yealink T</firstName>
     <lastName>27P</lastName>
     <groupId>communications</groupId>
     <extension>4676</extension>
    </directoryDetails>
    <groupDirectory>
    

    this is the xml i need to process.i need to access data according to nodes eg:name from