小编man*_*123的帖子

使用Python从XML文件编辑XML文本

我有一个XML文件,其中包含一些给定的数据.

<?xml version="1.0" encoding="UTF-8" ?> 
- <ParameterData>
  <CreationInfo date="10/28/2009 03:05:14 PM" user="manoj" /> 
- <ParameterList count="85">
- <Parameter name="Spec 2 Included" type="boolean" mode="both">
  <Value>n/a</Value> 
  <Result>n/a</Result> 
  </Parameter>
- <Parameter name="Spec 2 Label" type="string" mode="both">
  <Value>n/a</Value> 
  <Result>n/a</Result> 
  </Parameter>
- <Parameter name="Spec 3 Included" type="boolean" mode="both">
  <Value>n/a</Value> 
  <Result>n/a</Result> 
  </Parameter>
- <Parameter name="Spec 3 Label" type="string" mode="both">
  <Value>n/a</Value> 
  <Result>n/a</Result> 
  </Parameter>
  </ParameterList>
  </ParameterData>
Run Code Online (Sandbox Code Playgroud)

我有一个文本文件,行为

Spec 2 Included : TRUE
Spec 2 Label: 19-Flat2-HS3   
Spec 3 Included : FALSE
Spec 3 Label: 4-1-Bead1-HS3
Run Code Online (Sandbox Code Playgroud)

现在我想编辑XML文本; I,E.我想用文本文件中的相应值替换字段(n/a).就像我希望文件看起来像

<?xml …
Run Code Online (Sandbox Code Playgroud)

python xml

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

python ×1

xml ×1