Parser Module
XML parsing functionality for GS1 GPC.
This module provides classes for parsing GS1 GPC XML data and inserting it into a database.
The main class is GPCParser which handles parsing GPC XML files and inserting the data into a database. It supports callbacks for custom processing of GPC elements. A legacy function is provided for backward compatibility but new code should use the GPCParser class.
- class gs1_gpc.parser.GPCParser(db_connection, callback=None)[source]
Bases:
objectClass for parsing GS1 GPC XML data and inserting it into a database.
This class handles the parsing of GPC XML files and inserting the data into a database. It processes the hierarchical structure of GPC data (segments, families, classes, bricks, attribute types, and attribute values) and maintains counters for tracking the processing statistics.
It also supports callbacks for custom processing of GPC elements through the GPCProcessedCallback interface.
- __init__(db_connection, callback=None)[source]
Initialize a GPCParser.
- Parameters:
db_connection – Database connection object
callback (GPCProcessedCallback, optional) – Callback for processing events
- process_xml(xml_file_path)[source]
Parse GS1 GPC XML file and insert data into the database.
This method parses the GPC XML file, validates its structure, and processes all GPC elements (segments, families, classes, bricks, attribute types, and attribute values). It inserts the data into the database and builds an in-memory model of the GPC hierarchy.
If a callback is provided, it will be called for each element processed and when processing is complete.
- gs1_gpc.parser.process_gpc_xml(xml_file_path, db_connection, callback=None)[source]
Parse GS1 GPC XML file and insert data into the database.
This is a legacy function maintained for backward compatibility. New code should use the GPCParser class instead.
- Parameters:
xml_file_path (str) – Path to the GS1 GPC XML file
db_connection – Database connection object
callback (GPCProcessedCallback, optional) – Callback for processing events
- Returns:
Counters with processing statistics
- Return type: