import requests
import xml.etree.ElementTree as ET
import copy
import io
import pandas as pd
data = requests.get('<xml link>').text
#f = io.StringIO(data)
#root = ET.fromstring(data)
#root2 = ET.fromstring(data)
filename = "dc.xml"
tree = ET.parse(filename)
tree2 = ET.parse(filename)
root = tree.getroot()
root2 = tree2.getroot()
r2r = root2.find('./diagram/mxGraphModel/root')
for idx, c in enumerate(list(r2r)):
if idx > 2:
r2r.remove(c)
for item in r2r:
print(item.attrib['id'])
rep = {
'0': 6,
'1': 3,
'2': 3,
'3': 7,
'4': 6,
'5': 7,
'6': 7,
'7': 3,
'8': 5,
'9': 8,
'10': 6,
'11': 7,
'12': 8,
'13': 7,
'14': 7,
}
for idx, item in enumerate(root.find('diagram/mxGraphModel/root')):
if idx < 3: continue
rval = item.attrib.get('value', -1)
if rval[:2] == 'b2':
rval = 'b2'
print(rval)
if rval in rep:
print('rval', rval)
genid = item.attrib['value']
if 'text' in item.attrib['style']:
genid = f'text_{genid}'
else:
genid = f'bar_{genid}'
item.attrib['id'] = genid
item.attrib['value'] = ''
mx = item.find('./mxGeometry').attrib
mx_x = int(mx['x'])
mx_y = float(mx['y'])
for i in range(rep[rval]):
item2 = copy.deepcopy(item)
item2.attrib['id'] += str(i)
item2.find('./mxGeometry').attrib.update({
'y': str(mx_y+(i)*33)
})
r2r.insert(idx, item2)
#for i in range(rep[rval]):
# item2 = copy.deepcopy(item)
else:
item.attrib['id'] = rval
item.attrib['value'] = ''
r2r.insert(idx, item)
ids = [item.attrib['id'] for item in r2r]
df = pd.DataFrame(ids)
df[df.duplicated()]
tree = ET.ElementTree(root2)
tree.write(open('test.xml', 'w'), encoding='unicode')