XMLHandler
PLEXOS XML handler.
Import
Section titled “Import”from plexosdb import XMLHandlerConstructor
Section titled “Constructor”__init__(self, fpath: str | PathLike[str] | None=None, namespace: str=PLEXOS_NAMESPACE, in_memory: bool=True, initialize: bool=False) -> NoneInitialize XML handler for PLEXOS datasets.
Parameters
fpath : str or PathLike, optionalPath to an existing XML file to load.namespace : str, optionalXML namespace to use when serializing.in_memory : bool, optionalStore element caches in memory for faster lookups.initialize : bool, optionalBuild an empty XML tree instead of parsing a file.
Returns
None
Declared methods and properties
Section titled “Declared methods and properties”parse(cls, fpath: str | PathLike[str], namespace: str=PLEXOS_NAMESPACE, **kwargs: Any) -> 'XMLHandler'Return XML instance from file requested.
create_table_element
Section titled “create_table_element”create_table_element(self, rows: list[tuple[Any, ...]], column_types: dict[str, str], table_name: str) -> boolCreate XML elements for a given table.
get_records
Section titled “get_records”get_records(self, element_enum: Schema, *elements: Iterable[str | int], rename_dict: dict[str, str] | None=None, **tag_elements: Any) -> list[XMLRecord]Return XML text records without evaluating or coercing their contents.
Values are strings or None for empty elements. Schema-specific conversion belongs to the importer so numeric-looking text retains its spelling.
iter(self, element_type: Schema, *elements: Iterable[str | int], label: str | None=None, **tags: Any) -> Iterable[ET.Element]Return elements from the XML based on the type.
This functions serves as a low-level query to the XML file.
Parameters
element_typeEnum of the Schema wanted, e.g.,Schema.Class,Schema.Objects.*elementsSequence of ids, strings, or ints to get.labelXML child label to extract. Defaults toSchema[elementy_type].label.**tagsAdditional key: value pairs to match the XML, e.g.,kwargs = {"class_id": 1}.
Return
XML query match.
to_xml
Section titled “to_xml”to_xml(self, fpath: str | PathLike[str]) -> boolSave memory xml to file.