I am trying to convert the Person
Typescript object to XML, but it is not including the "CAR" tag inside the conversion, how can I achieve this?
Already tried with the libraries js2xmlparser and xml-js, working with Angular 8 and tried with JSON.Stringify() but the same result comes up in JSON, the Typescript array gets encoded without the name of the object it has nested inside.
export class Person {
...
CarsList: Car[];
constructor() {
this.CarsList = [];
}
}
export class Car {
...
Parts: Parts[];
Model: string;
...
}
The code that I am actually using to encode into xml is the following:
import * as xmlJs from 'xml-js';
// This is using the xml-js library to generate the xml in the return
getWithXmlJsLibrary(obj: Person) {
const options = { compact: true, ignoreComment: true, spaces: 4 };
return xmlJs.js2xml(obj, options); // js2xml
}
Expected result is
<Person>
<CarsList>
<Car>
<Model>value</Model>
</Car>
<Car>
<Model>value</Model>
</Car>
<Car>
<Model>value</Model>
</Car>
</Carslist>
</Person>
But the actual result is
<Person>
<CarsList>
<Model>value</Model>
<Model>value</Model>
...
</Carslist>
</Person>