Base Parser

Base class of parsers.

class benker.parsers.base_parser.BaseParser(builder, encoding='utf-8', **options)

Bases: object

Abstract base class of the parsers classes.

parse_file(src_xml, dst_xml)

Parse and convert the tables from one format to another.

Parameters:
  • src_xml (str) – Source path of the XML file to convert.
  • dst_xml (str) – Destination path of the XML file to produce.

Changed in version 0.5.0: Always generate the XML declaration in the destination file.

transform_tables(tree)
benker.parsers.base_parser.value_of(element, xpath, namespaces=None, default=None)

Take the first value of a xpath evaluation.

Parameters:
  • element (etree._Element) – Root element used to evaluate the xpath expression.
  • xpath (str) – xpath expression. This expression will be evaluated using the namespaces namespaces.
  • namespaces (dict[str, str]) – Namespace map to use for the xpath evaluation.
  • default – default value used if the xpath evaluation returns no result.
Returns:

the first result or the default value.