builder – XML Builder Module¶
- class lazyxml.builder.Builder(**kw)¶
XML Builder
- set_options(**kw)¶
Set Builder options.
See also
kw argument have the same meaning as in lazyxml.dumps()
- get_options()¶
Get Builder options.
- dict2xml(data)¶
Convert dict to xml.
Warning
DEPRECATED: dict2xml() is deprecated. Please use object2xml() instead.
Deprecated since version 1.2.
- object2xml(data)¶
Convert python object to xml string.
Parameters: data – data for build xml. If don’t provide the root option, type of data must be dict and len(data) == 1. Return type: str or unicode New in version 1.2.
- build_xml_header()¶
Build xml header include version and encoding.
Return type: str
- build_tree(data, tagname, attrs=None, depth=0)¶
Build xml tree.
Parameters: - data – data for build xml.
- tagname – element tag name.
- attrs (dict or None) – element attributes. Default:None.
- depth (int) – element depth of the hierarchy. Default:0.
- check_structure(keys)¶
Check structure availability by attrkey and valuekey option.
- pickdata(data)¶
Pick data from attrkey and valuekey option.
Returns: a pair of (attrs, values) Return type: tuple
- safedata(data, cdata=True)¶
Convert xml special chars to entities.
Parameters: - data – the data will be converted safe.
- cdata (bool) – whether to use cdata. Default:True. If not, use cgi.escape() to convert data.
Return type: str
- build_tag(tag, text='', attrs=None)¶
Build tag full info include the attributes.
Parameters: - tag – tag name.
- text – tag text.
- attrs (dict or None) – tag attributes. Default:None.
Return type: str
- tag_start(tag, attrs=None)¶
Build started tag info.
Parameters: - tag – tag name
- attrs (dict or None) – tag attributes. Default:None.
Return type: str
- tag_end(tag)¶
Build closed tag info.
Parameters: tag – tag name Return type: str