-
-
Save ValchanOficial/92b298bf7795275c6f85663129f8f10f to your computer and use it in GitHub Desktop.
Revisions
-
Aravin revised this gist
Sep 11, 2018 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,4 +32,18 @@ // Result toJson(employeeXml); toXML(employeeJson); //// /// SAMPLE OUTPUT //// { Employee: { name: 'Aravind', age: '24', sex: 'Male' } } <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Employee> <name>Aravind</name> <age>24</age> <sex>Male</sex> </Employee>
-
Aravin created this gist
Sep 11, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ import { parseString, Builder } from "xml2js"; // Convert string/XML to JSON function toJson(xml: string) { parseString(xml, { explicitArray: false }, function(error, result) { console.log(result); }); } // Convert string/JSON to XML function toXML(json: string) { const builder = new Builder(); console.log(builder.buildObject(json)); } // Test Data const employeeJson: any = { Employee: { name: 'Aravind', age: 24, sex: 'Male' } }; const employeeXml = "<Employee><name>Aravind</name><age>24</age><sex>Male</sex></Employee>" // Result toJson(employeeXml); toXML(employeeJson);