labapi.util.extract.extract_etree#

labapi.util.extract.extract_etree(
_etree: Element,
schema: EtreeExtractorDict,
*,
raise_missing: bool = True,
) dict[str, Any][source]#

Extract data from an lxml.etree.Element using a format dictionary.

This function navigates the XML tree using paths defined in the schema dictionary and applies callable extractors to the text content of the found elements.

Parameters:
  • _etree – The lxml.etree.Element from which to extract data.

  • schema – A dictionary defining the structure and extraction logic. Keys are XML element tags (or paths), and values are either nested EtreeExtractorDict or callable functions to process the text.

  • raise_missing – Whether to treat absent or unmappable values as errors. When true, either raises ExtractionError. When false, the value is omitted from the result instead: silently if the element is absent, and with a RuntimeWarning if it is present but a callable extractor rejects it.

Returns:

A dictionary containing the extracted and processed data.

Raises:

ExtractionError – If raise_missing is true and a requested element is missing, or a callable extractor fails to process a value.