From e6b65539973dde1ad9d17aa07ada5e52239ec1a5 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Wed, 7 Aug 2024 13:23:23 +0700 Subject: [PATCH] Create xcmp_adapter.py --- .../interoperability/xcmp/xcmp_adapter.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 projects/DAPIO/interoperability/xcmp/xcmp_adapter.py diff --git a/projects/DAPIO/interoperability/xcmp/xcmp_adapter.py b/projects/DAPIO/interoperability/xcmp/xcmp_adapter.py new file mode 100644 index 000000000..54cf48c5b --- /dev/null +++ b/projects/DAPIO/interoperability/xcmp/xcmp_adapter.py @@ -0,0 +1,19 @@ +import xml.etree.ElementTree as ET + +class XCMPAdapter: + def __init__(self, namespace: str): + self.namespace = namespace + + def convert_to_xcmp(self, data: dict) -> ET.Element: + root = ET.Element("XCMP", xmlns=self.namespace) + for key, value in data.items(): + element = ET.SubElement(root, key) + element.text = str(value) + return root + + def convert_from_xcmp(self, xcmp: ET.Element) -> dict: + data = {} + for element in xcmp.iter(): + if element.text: + data[element.tag] = element.text + return data