You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add xml2json function for easy conversion of xml string to json
Why ?
We need to traverse the XML response from a SOAP based API into a json object so that we can easily map and transform the data
Why not use parseXML?
Well we have tried using parseXML to traverse the XML response but it's not easy to map the XML response, You have to go through the cheerio documentation and figure out how to traverse the xml response
The approach above might work but it's difficult to troubleshoot, there is no documentation for it on our adaptors and not easy getting proper mapping that you can confidently trust not to break
Side Note
Currently cheerio [The library we are using behind parseXML] has a method called $.exctract which seems to provide a simple interface for extracting data from HTML document. The down side is although this function is documented, it not release yet [See GitHub issue here]. A library that was born out of that GitHub issue - https://github.com/denkan/cheerio-json-mapper which might be useful for adding $.exctract ability in parseXML
Implementation Note
Add xml2json function with the following signature
See options list here - https://github.com/Leonidas-from-XIV/node-xml2js?search=1#options
interface Xml2JsonOptions {
[key: string]: any;
}
xml2json(xmlString: string, options: Xml2JsonOptions, callback: (state: any) => any))
The text was updated successfully, but these errors were encountered:
Short Summary
Add
xml2json
function for easy conversion of xml string to jsonWhy ?
We need to traverse the XML response from a SOAP based API into a json object so that we can easily map and transform the data
Why not use
parseXML
?Well we have tried using
parseXML
to traverse theXML
response but it's not easy to map the XML response, You have to go through the cheerio documentation and figure out how to traverse the xml responseSee example here 👇🏽
The approach above might work but it's difficult to troubleshoot, there is no documentation for it on our adaptors and not easy getting proper mapping that you can confidently trust not to break
Side Note
Currently cheerio [The library we are using behind
parseXML
] has a method called $.exctract which seems to provide a simple interface for extracting data from HTML document. The down side is although this function is documented, it not release yet [See GitHub issue here]. A library that was born out of that GitHub issue - https://github.com/denkan/cheerio-json-mapper which might be useful for adding$.exctract
ability inparseXML
Implementation Note
Add
xml2json
function with the following signatureThe text was updated successfully, but these errors were encountered: