/
xml
xml
Functions
[string] asJSON([string] xml) // convert an xml string to json string
Examples
Simple convert
Convert an xml string to a json string and print it
var myXml="<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>"; print(xml.asJSON(myXml));
Output:
{"note":{"heading":"Reminder","from":"Jani","to":"Tove","body":"Don't forget me this weekend!"}}
Load remotely, convert and use data
Load an xml from W3schools convert it to json object and print a table based on that
var myXml=http.get("https://www.w3schools.com/XML/note.xml"); var myJson=JSON.parse(xml.asJSON(myXml)); var from=myJson.note.from; var to=myJson.note.to; out.table(["from","to"],[[from,to]]);
Output:
from | to |
---|---|
Jani | Tove |