XML Handler
Public module members
Section titled “Public module members”plexosdb.xml_handler
Section titled “plexosdb.xml_handler”PLEXOS_NAMESPACE
Section titled “PLEXOS_NAMESPACE”PLEXOS_NAMESPACE = 'http://tempuri.org/MasterDataSet.xsd'XMLHandler
Section titled “XMLHandler”PLEXOS XML handler.
Methods and properties
Section titled “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.
Full reference: XMLHandler.
xml_query
Section titled “xml_query”Construct XPath query for extracting data from a XML with no namespace.
Parameters
element_nameString that matches the desired element*tagsTag names to filter**kwargsTag name and value child of the element. (E.g., class_id=2)
Returns
XPath query string constructed based on the provided conditions.
Examples
A simple example for one condition:
>>> query_string = xml_query("t_object", class_id="2")>>> print(query_string)".//t_object[class_id='2']"For multiple condition:
>>> query_string = xml_query("t_object", class_id="2", enum_id="1")>>> print(query_string)".//t_object[class_id='2'][enum_id='1']"xml_query(element_name: str, *tags: Any, **tag_elements: Any) -> str