I am trying to map an xml response (it uses text XMLHttpRequestResponseType) from a backend server to a typescript interface. Right now, I tried to use xml2js to map the xml into a JSON and then map the JSON to the typescript interface (I am working with Angular 5). the problem is that xml2js will render the following:
Let's say we have the following xml:
<xmlTag attr1="value1" attr2="value2>
<innerTag attr3="value3">value4</innerTag>
</xmlTag>
The way that the interfaces are defined is the following:
export interface XmlTag {
attr1?: string;
attr2?: string;
innerTag?: InnerTag;
}
export interface InnerTag {
attr3?: string;
innerTagValue?: string;
}
The problm is that xml2js maps xml attributes with '$' as e key and a nested json object as its value. Example:
<xmlTag attr1="value1" attr2="value2>
<innerTag attr3="value3">value4</innerTag>
</xmlTag>
gets transformed into: image
So a '$' is used as a key for tag attributes and a nested json object as a value, containing all the attributes and a '_' for the value between the tags.
When I need to bind it inside an HTML page I have to access (for example attr3) by using {{innerTag.$.attr3}}, rendering my interface useless.
Is there any way (library maybe) to map the response to the interface (every xml tag should be an interface and the interfaces' attributes being the xml tag attributes and the nested tags)? Or I have to manually do it?
Thank you!