xl

xml without mess.

This is a Python module to process XML.

Why I am coding this?

  • lxml supports sub text node not clear enough.
  • xml.etree.ElementTree doesn’t care XML namespaces.
  • I want to learn XML.
epubaker.xl.parse(xmlstr, debug=False)

parse XML string to Xl object

Parameters:
  • xmlstr (str) –
  • debug (bool) –
Returns:

object of Xl

Return type:

Xl

epubaker.xl.clean_whitespaces(element)
Parameters:element
Returns:A copy of the element, all whitespace characters have been stripped from the beginning and the end of the text node in the children and children’s children and so on. delete the text node If it is empty.
epubaker.xl.pretty_insert(element, start_indent=0, step=4, dont_do_when_one_child=True)

Modify the copy of the element, to make it looks more pretty and clear.

Parameters:
  • element (Element) –
  • start_indent (int) –
  • step (int) –
  • dont_do_when_one_child (bool) –
Returns:

object of Element

class epubaker.xl.Xl(header=None, doc_type=None, root=None)
Parameters:
header = None

object of Header

doc_type = None

object of DocType

root = None

object of Element

string()

To xml string

class epubaker.xl.Header(version=None, encoding=None, standalone=None)

Handle XML header node

Parameters:
  • version (str) –
  • encoding (str) –
  • standalone (bool) –
class epubaker.xl.DocType(doc_type_name, system_id, public_id)

Handle XML doc type node

class epubaker.xl.Element(tag=None, attributes=None, prefixes=None)

Handle XML element node.

tag

tuple object of length 2.

First in the tuple is the url of the namespaces, the second is the xml element tag you know ordinarily.

string(inherited_prefixes=None)

to string, you may want to see Xl.string