项目作者: payneal

项目描述 :
convert json object to xml and xml string to json object
高级语言: JavaScript
项目地址: git://github.com/payneal/json_xml_converter.git
创建时间: 2018-01-15T16:36:23Z
项目社区:https://github.com/payneal/json_xml_converter

开源协议:

下载


JSON XML Converter

to run test

  • git clone repo
  • cd xml_and_json
  • npm install
  • npm run test

how libary works

  • to create converter ex.

    1. const Converter = require('../json_to_xml_converter');
    2. let converter = new Converter();
  • to convert a json object to xml

    1. var args = JSON_OBJECT
    2. var json_object = converter.json_to_xml(args);
  • to convert xml to json object

    1. var args = XML_STRING
    2. var xml_string = converter.xml_to_json(args);
  • to tell converter that the xml string you are passing in has array elements
    ```javascript

    1. var args = {
    2. umm: {
    3. attributes: {
    4. x: '10',
    5. },
    6. hold: [
    7. {count:"0"},
    8. {count:"1"}
    9. ]
    10. }
    11. };
    12. var valid_xml = `
    13. <umm x="10">
    14. <hold>
    15. <count>0</count>
    16. <count>1</count>
    17. </hold>
    18. </umm>`
    19. converter.add_elements_that_are_arrays(["hold"]);
    20. var xml = converter.json_to_xml(args);
    21. expect(valid_xml).xml.to.equal(xml);

    });

  1. * to clear the array possibilities for xml to json
  2. ```javascript
  3. converter.clear_xml_array_name();
  • needs another featuer implemented to handdle xml array within an array element
    1. //not implemented