1

How to set XML response into model.

This is the model class

export class Region {
    public regionCode : number;
    public regionName : string;
}

This is how I had done with JSON data

Component

typeMasterList: Region [];

this.masterDataService.typeMaster().subscribe(response => {
    this.typeMasterList = response['requests'];
});

This is what I tried with XML.

Sample request

<requests>
   <region>
      <regionCode>50002</regionCode>
      <regionName>STUV</regionName>
   </region>
   <region>
      <regionCode>50003</regionCode>
      <regionName>AINL</regionName>
   </region>
</requests>

I had added this in http get call { responseType: 'text' }

this.masterDataService.typeMaster().subscribe(response => {
     console.log("key :"+data); // displays  full text.
    this.typeMasterList = response['requests']; // but this not working, as its xml response.
});

How can I assign the response to the array ?

IsraGab
  • 4,819
  • 3
  • 27
  • 46
user630209
  • 1,123
  • 4
  • 42
  • 93
  • 3
    Possible duplicate of [How to deserialize XML to JavaScript/TypeScript?](https://stackoverflow.com/questions/24678534/how-to-deserialize-xml-to-javascript-typescript) – Boland Aug 27 '18 at 04:09

0 Answers0