json2xml package¶
Submodules¶
json2xml.dicttoxml module¶
Converts a Python dictionary or other native data type into a valid XML string.
- Supports item (int, float, long, decimal.Decimal, bool, str, unicode, datetime, none and other
- number-like objects) and collection (list, set, tuple and dict, as well as iterable and
dict-like objects) data types, with arbitrary nesting for the collections.
Items with a datetime type are converted to ISO format strings. Items with a None type become empty XML elements.
This module works with Python 3.7+
- json2xml.dicttoxml.convert(obj, ids, attr_type, item_func, cdata, item_wrap, parent='root')[source]¶
Routes the elements of an object to the right function to convert them based on their data type
- json2xml.dicttoxml.convert_bool(key, val, attr_type, attr={}, cdata=False)[source]¶
Converts a boolean into an XML element
- json2xml.dicttoxml.convert_dict(obj, ids, parent, attr_type, item_func, cdata, item_wrap)[source]¶
Converts a dict into an XML string.
- json2xml.dicttoxml.convert_kv(key, val, attr_type, attr={}, cdata: bool = False)[source]¶
Converts a number or string into an XML element
- json2xml.dicttoxml.convert_list(items, ids, parent, attr_type, item_func, cdata, item_wrap)[source]¶
Converts a list into an XML string.
- json2xml.dicttoxml.convert_none(key, val, attr_type, attr={}, cdata=False)[source]¶
Converts a null value into an XML element
- json2xml.dicttoxml.dicttoxml(obj, root: bool = True, custom_root='root', ids=False, attr_type=True, item_wrap=True, item_func=<function default_item_func>, cdata=False)[source]¶
Converts a python object into XML. Arguments: - root specifies whether the output is wrapped in an XML root element
Default is True
custom_root allows you to specify a custom root element. Default is ‘root’
ids specifies whether elements get unique ids. Default is False
attr_type specifies whether elements get a data type attribute. Default is True
item_func specifies what function should generate the element name for items in a list. Default is ‘item’
item_wrap specifies whether to nest items in array in <item/> Default is True
cdata specifies whether string values should be wrapped in CDATA sections. Default is False
json2xml.json2xml module¶
json2xml.utils module¶
Utils methods to convert XML data to dict from various sources
Module contents¶
Top-level package for json2xml.