我有以下问题:我有一个xml文件,我正在通过它进行解析xml.etree.ElementTree文件其结构如下
<e3r>
<moreData>false</moreData>
<data>
<CashDividend Isin="IE00BYM8JD58" AdjustmentFactor="" Adjustment_Date="" Adjustment_Factor=""/>
<CashDividend Isin="IE00BZ163G84" AdjustmentFactor="" Adjustment_Date="" Adjustment_Factor="" Amount_Status=""/>
<CashDividend Isin="IE00BZ163H91" AdjustmentFactor="" Adjustment_Date="" Adjustment_Factor=""/>
<CashDividend Isin="IE00BZ163M45 " AdjustmentFactor="" Adjustment_Date="" Adjustment_Factor="" />
</data>
</e3r>
我正在通过一个API(在这里我使用Isin来获取数据)获取标签AdjustmentFactor的一些数据,我想要实现的是将通过API获得的数据添加到AdjustmentFactor。(与Isin有关)。我怎么也解决不了这个问题。你知道吗
我就是这样得到每个ISIN的:
isins = []
for child in tree.getroot().getchildren()[1].getchildren():
isins.append(child.attrib['Isin'])
for isin in isins:
print isin
但我不知道如何使用列表isins中存储的数据向AdjustmentFactor添加数据。你知道吗
有人能帮忙吗?你知道吗
问题中没有明确说明,但是如果我理解正确,您需要更新元素的
AdjustmentFactor
属性值,其中Isin
属性等于某个值。您可以使用类似于.//element_name[@attribute_name='attribute_value']
的XPath表达式,通过元素的属性值来查找元素。你知道吗工作演示示例:
^{}
输出:
相关问题 更多 >
编程相关推荐