我有这个XML文件:
<?xml version="1.0" ?><XMLSchemaPalletLoadTechData xmlns="http://tempuri.org/XMLSchemaPalletLoadTechData.xsd">
<TechDataParams>
<RunNumber>sample</RunNumber>
<Holder>sample</Holder>
<ProcessToolName>sample</ProcessToolName>
<RecipeName>sample</RecipeName>
<PalletName>sample</PalletName>
<PalletPosition>sample</PalletPosition>
<IsControl>sample</IsControl>
<LoadPosition>sample</LoadPosition>
<HolderJob>sample</HolderJob>
<IsSPC>sample</IsSPC>
<MeasurementType>sample</MeasurementType>
</TechDataParams>
<TechDataParams>
<RunNumber>sample</RunNumber>
<Holder>sample</Holder>
<ProcessToolName>sample</ProcessToolName>
<RecipeName>sample</RecipeName>
<PalletName>sample</PalletName>
<PalletPosition>sample</PalletPosition>
<IsControl>sample</IsControl>
<LoadPosition>sample</LoadPosition>
<HolderJob>sample</HolderJob>
<IsSPC>sample</IsSPC>
<MeasurementType>XRF</MeasurementType>
</TechDataParams>
</XMLSchemaPalletLoadTechData>
这是我解析xml的代码:
^{pr2}$但是当我打印每个节点时,我只得到一组“TechDataParams”,但我希望能够从XML中获取所有“TechDataParams”。在
如果我的问题有点不清楚,请告诉我。在
请不要使用
minidom
解析XML,除非您希望自己拔出头发。在我在这里用^{} module 。一行,您就有一个包含所有所需数据的dict列表:
印刷品:
^{pr2}$这里有一个例子给你。将
file_path
替换为您自己的。在我将}。在
RunNumber
的值替换为001
和{输出:
^{pr2}$也是通过
lxml.etree
模块。在http://tempuri.org/XMLSchemaPalletLoadTechData.xsd
xpath
方法查找目标TechDataParams
标记。在TechDataParams
标记的子项并创建字典,其中key
是{TechDataParams
。在代码:
输出:
^{pr2}$相关问题 更多 >
编程相关推荐