builder
– XML Builder Module¶
-
class
lazyxml.builder.
Builder
(encoding=None, header_declare=True, version=None, root=None, cdata=True, indent=None, ksort=False, reverse=False, errors='strict', hasattr=False, attrkey=None, valuekey=None)¶ Simple xml builder
-
dict2xml
(data)¶ Convert dict to xml.
Warning
DEPRECATED:
dict2xml()
is deprecated. Please useobject2xml()
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 ofdata
must be dict andlen(data) == 1
.Return type: str or unicode New in version 1.2.
-
static
build_xml_header
(encoding=None, version=None)¶ Build xml header include version and encoding.
-
build_tree
(data, tagname, attrs=None, depth=0)¶ Build xml tree.
Parameters:
-
check_structure
(keys)¶ Check structure availability by
attrkey
andvaluekey
option.
-
pickdata
(data)¶ Pick data from
attrkey
andvaluekey
option.Returns: a pair of (attrs, values) Return type: tuple
-
static
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, usecgi.escape()
to convert data.
Return type:
-
classmethod
build_tag
(tag, text='', attrs=None)¶ Build tag full info include the attributes.
Parameters: Return type:
-
static
build_attr
(attrs)¶ Build tag attributes.
Parameters: attrs (dict) – tag attributes Return type: str
-
classmethod
tag_start
(tag, attrs=None)¶ Build started tag info.
Parameters: Return type:
-