flow_inference.xml_processing.XMLProcessor

class flow_inference.xml_processing.XMLProcessor(xml_file)[source]

Process PAGE XML documents and insert OCR/HTR inference results.

The processor wraps an XML tree, keeps track of the document namespace, and provides helpers for creating and replacing TextEquiv elements. It can update matching TextLine elements with inferred text and add collected region-level text to the corresponding TextRegion elements.

Parameters:

xml_file (str)

__init__(xml_file)[source]

Load and parse a PAGE XML file.

Parameters:

xml_file (str) – Path to the XML file to parse.

Raises:
Return type:

None

Methods

__init__(xml_file)

Load and parse a PAGE XML file.

create_text_equiv_element(text)

Create a TextEquiv element with one Unicode child.

from_string(xml_content)

Create an XMLProcessor instance from an XML string.

insert_inferred_lines(root, inferred_lines)

Insert inferred text into PAGE XML.

replace_direct_text_equiv(element, text)

Replace only direct TextEquiv children of the given element.

tree_to_string()

Serialize the XML tree to a string.