[lxml-dev] XMLParser + XMLFormatter ?

Hi,
Andreas requested a new feature that mainly relates to output formatting. The obvious API for it might be a new keyword argument.
However, since we seem to be getting more and more keyword arguments in the I/O functions, maybe we should rethink the way we set options on output methods. Fredrik mentioned the possibility to have an XMLParser that only wrapps options like this:
class XMLParser: def __init__(self, **options): self.options = options
doc = ET.parse(source, parser=XMLParser(configuration))
What about doing the same with output options? Imagine this:
class XMLFormatter: def __init__(self, xhtml=False, pretty_print=False, indent=4, ...): self.options = {} ...
xml_text = ET.write_str(XMLFormatter(pretty_print=True))
That would give us a nice, symmetric API for input and output options.
If you prefer, you could easily use sublasses to provide different default arguments:
class XMLPrettyPrinter(XMLFormatter): def __init__(..., pretty_print=True, ...):
Comments?
Stefan
participants (1)
-
Stefan Behnel