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 raise ExtractionError when a requested element is missing. When false, missing values are omitted from the result.

Returns:

A dictionary containing the extracted and processed data.

Raises:

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