我的xml文件是这样的
<S_Row>
<S_Cell><S_CellBody></S_CellBody></S_Cell>
<S_Cell><S_CellBody></S_CellBody></S_Cell>
<S_Cell><S_CellBody></S_CellBody></S_Cell>
</S_Row>
我在python中这样处理它:
for i, S_Cell in enumerate(S_Row.findall('S_Cell')):
for S_CellBody in S_Cell.getchildren():
if i==0:
S_CellBody.text="ABC"
这将在xml文件中提供如下输出:
<S_Row>
<S_Cell><S_CellBody>ABC</S_CellBody></S_Cell>
<S_Cell><S_CellBody></S_CellBody></S_Cell>
<S_Cell><S_CellBody></S_CellBody></S_Cell>
</S_Row>
现在,如果我想添加另一行并在第二行(第1列)中添加如下元素:
<S_Row>
<S_Cell><S_CellBody>ABC</S_CellBody></S_Cell>
<S_Cell><S_CellBody></S_CellBody></S_Cell>
<S_Cell><S_CellBody></S_CellBody></S_Cell>
</S_Row>
<S_Row>
<S_Cell><S_CellBody>DEF</S_CellBody></S_Cell>
<S_Cell><S_CellBody></S_CellBody></S_Cell>
<S_Cell><S_CellBody></S_CellBody></S_Cell>
</S_Row>
我该怎么办?你知道吗
将一个字符串视为XMLstring
相关问题 更多 >
编程相关推荐