Skip to content

Commit

Permalink
Create xcmp_adapter.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 7, 2024
1 parent 22d67f1 commit e6b6553
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions projects/DAPIO/interoperability/xcmp/xcmp_adapter.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e6b6553

Please sign in to comment.