utilities
tostring
This utility method can be called on any _Base
subclass objects and returns a string representation of the ElementTree object.
prettify
This utility method can be called on any _Base
subclass objects and returns a formatted, prettified string representation of the ElementTree object.
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) |
You can use simplejson.dumps()
or json.dumps()
to convert the JSON string into a JSON object. Tag text is accessed using standard key[value]
syntax, and tag attributes are accessed using @attrib
syntax. Any tails within a tag are accessed using #tail
syntax.
Last updated