labapi.util.extract.extract_etree#
- labapi.util.extract.extract_etree(
- _etree: Element,
- schema: EtreeExtractorDict,
- *,
- raise_missing: bool = True,
Extract data from an
lxml.etree.Elementusing 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
ExtractionErrorwhen 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_missingis true, or if a callable extractor fails to process a value.