def parse(input, pyformat, sort_keys, **kwargs): """ Converts the input into a structured object hierarchy. Requires valid input. """ if not input: input = '-' with click.open_file(input, mode='rb') as f: xmlstring = f.read() output = xml_utils.xml_to_json(xmlstring, strip_whitespace=False, strip_namespace=False, strip_attribute=False, pretty=True) d = json.loads(output) if pyformat: s = pformat(d) else: s = json.dumps(d, indent=2, sort_keys=sort_keys) click.echo(s)
def tojson(input, pretty, echo, strip_whitespace, strip_namespace, strip_attribute, **kwargs): """ Converts the XML input to JSON output. Requires valid input. """ # output = xml2json.json2xml(input) if not input: input = '-' with click.open_file(input, mode='rb') as f: xmlstring = f.read() if echo: click.echo('\nXML:') click.echo(xmlstring) click.echo('\nJSON:') output = xml_utils.xml_to_json(xmlstring, strip_whitespace=strip_whitespace, strip_namespace=strip_namespace, strip_attribute=strip_attribute, pretty=pretty) # output = xml2json.elem2json(dom, options=options, strip_ns=None, strip=None) # click.echo('\nJSON:\n{}\n'.format(output)) click.echo(output)