Код: Выделить всё
xml_s = """
Data
https:///1f3a6012-d6b2-4258-a91a-fc6d4e86c304/Data
2024-07-18T05:22:18Z
[*]
5746
uuid:58aaa654-1649-4061-97fe-ecc53e186fee;id=1
2024-07-18T05:22:18Z
1
491
Amine > Shared
Vertical Heads Approval
1
2022-11-15T15:01:17
uuid:58aaa654-1649-4061-97fe-ecc53e186fee;id=2
2024-07-18T05:22:18Z
2
586
Ruby > DNB-NT
XYZ
Vertical Heads Approval
1
2022-12-07T14:14:19
"""
Код: Выделить всё
import pandas as pd
import xml.etree.ElementTree as ET
x = ET.parse(xml_s)
root = x.getroot()
s = ET.tostring(root).decode()
namespace =
{'ns_0': 'http://www.w3.org/2005/Atom',
'ns_1': 'http://schemas.microsoft.com/ado/2007/08/dataservices',
'ns_2': 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata'}
df = pd.read_xml(s,namespaces = namespace, xpath='.//properties')
Код: Выделить всё
ValueError: xpath does not return any nodes. Be sure row level nodes are in xpath. If
document uses namespaces denoted with xmlns, be sure to define namespaces and use them
in xpath.
Итак, мой вопрос будет таким:
- Как я могу динамически идентифицировать «последний дочерний узел» любого XML. Я предполагаю, что в «последнем дочернем узле» будут присутствовать фактические данные.
- Поскольку в этом случае последний дочерний узел был связан с пространством имен m, как это сопоставление можно сделать динамически?
Подробнее здесь: https://stackoverflow.com/questions/787 ... lly-in-xml