Beispiel #1
0
 def test_json_from_file_works(self):
     data = Json2xml.fromjsonfile('examples/example.json').data
     data_object = Json2xml(data)
     xml_output = data_object.json2xml()
     dict_from_xml = xmltodict.parse(xml_output)
     # since it's a valid XML, xml to dict is able to load it and return
     # elements from under the all tag of xml
     self.assertTrue(type(dict_from_xml['all']) == OrderedDict)
Beispiel #2
0
def json2xml(jsonfile, URL=False):
    try:
        from src.json2xml import Json2xml
    except:
        return "PLEASE INSTALL JSON2XML"
        break
    if URL == False:
        data = Json2xml.fromjsonfile(jsonfile).data
        data_object = Json2xml(data)
Beispiel #3
0
def main(argv=None):
    parser = argparse.ArgumentParser(description='Utility to convert json to valid xml.')
    parser.add_argument('--url', dest='url', action='store')
    parser.add_argument('--file', dest='file', action='store')
    args = parser.parse_args()

    if args.url:
        url = args.url
        data = Json2xml.fromurl(url)
        print(Json2xml.json2xml(data))

    if args.file:
        file = args.file
        data = Json2xml.fromjsonfile(file)
        print(Json2xml.json2xml(data))
Beispiel #4
0
 def test_is_json_from_file_works(self):
     data = Json2xml.fromjsonfile('examples/example.json').data
     data_object = Json2xml(data)
     xml_output = data_object.json2xml()
     htmlkeys = xml_output.XML_FORMATTERS.keys()
     self.assertTrue('html' in htmlkeys)