utilities
tostring
This utility method can be called on any _Base subclass objects and returns a string representation of the ElementTree object.
my_date = datatypes.Datatype(
'Date',
{
'month': '03',
'day': '14',
'year': '2012',
'hour': '08',
'minute': '35',
'second': '43'
}
)
print(my_date.tostring())
>>> b'<Date><hour>08</hour><month>03</month><second>43</second><year>2012</year><day>14</day><minute>35</minute></Date>'prettify
This utility method can be called on any _Base subclass objects and returns a formatted, prettified string representation of the ElementTree object.
my_date = datatypes.Datatype(
'Date',
{
'month': '03',
'day': '14',
'year': '2012',
'hour': '08',
'minute': '35',
'second': '43'
}
)
print(my_date.prettify())
>>> b'''
<?xml version="1.0" encoding="utf-8"?>
<Date>
<hour>08</hour>
<month>03</month>
<second>43</second>
<year>2012</year>
<day>14</day>
<minute>35</minute>
</Date>
'''xml2json
This utility method converts an XML string into a JSON string, which for some users will be easier to work with than an XML string. An example for this helper method can be found below.
attribute
type
description
xmlstring
String
an XML string
strip
Bool
string whitespace (default: True)
Last updated