我想在python中将XML文件转换为CSV文件。下面我附上一张照片的霍姆XML文件看起来像,我想为每个id(如PZH01\u MST\u 0690\u 00)采取最低流量,在这种情况下,它将是:60。有人能帮我吗?我想有经验的人做这件事相当容易。基本上,我想将这个XML文件转换成CSV文件,并有2列(1列具有id,2列具有最低的流量)。任何帮助都将不胜感激,谢谢!你知道吗
<?xml version="1.0" encoding="UTF-8"?>
-<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
-<SOAP:Body>
-<d2LogicalModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" modelBaseVersion="2" xmlns="http://datex2.eu/schema/2/2_0">
-<exchange>
-<supplierIdentification>
<country>nl</country>
<nationalIdentifier>NLNDW</nationalIdentifier>
</supplierIdentification>
</exchange>
-<payloadPublication lang="nl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="MeasuredDataPublication">
<publicationTime>2019-10-31T11:12:42.005Z</publicationTime>
-<publicationCreator>
<country>nl</country>
<nationalIdentifier>NLNDW</nationalIdentifier>
</publicationCreator>
<measurementSiteTableReference targetClass="MeasurementSiteTable" version="1139" id="NDW01_MT"/>
-<headerInformation>
<confidentiality>noRestriction</confidentiality>
<informationStatus>real</informationStatus>
</headerInformation>
-<siteMeasurements xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<measurementSiteReference targetClass="MeasurementSiteRecord" version="6" id="PZH01_MST_0690_00"/>
<measurementTimeDefault>2019-10-31T11:11:00Z</measurementTimeDefault>
-<measuredValue index="1">
-<measuredValue>
-<basicData xsi:type="TrafficFlow">
-<vehicleFlow>
<vehicleFlowRate>720</vehicleFlowRate>
</vehicleFlow>
</basicData>
</measuredValue>
</measuredValue>
-<measuredValue index="2">
-<measuredValue>
-<basicData xsi:type="TrafficFlow">
-<vehicleFlow>
<vehicleFlowRate>60</vehicleFlowRate>
</vehicleFlow>
</basicData>
</measuredValue>
</measuredValue>
-<measuredValue index="3">
-<measuredValue>
-<basicData xsi:type="TrafficFlow">
-<vehicleFlow>
<vehicleFlowRate>60</vehicleFlowRate>
</vehicleFlow>
</basicData>
</measuredValue>
</measuredValue>
-<measuredValue index="4">
-<measuredValue>
-<basicData xsi:type="TrafficFlow
我建议您使用
python-benedict
,它是一个dict
子类,支持从/到最常见格式的I/O操作,包括xml
和csv
。你知道吗安装:
pip install python-benedict
文档:https://github.com/fabiocaccamo/python-benedict
非常简单:)
相关问题 更多 >
编程相关推荐