时间:2011-01-10 23:34:41

标签: python lxml

我正在迭代xml节点值,这是我从xpath查询得到的。我需要为某个节点值分配一个引用。

这就是我想要的:

from lxml import etree

doc = etree.fromstring(some_xml)
nodes = doc.xpath('some_query')
for node in nodes:
    if node.text == 'smth':
        #there i need to assign reference
        reference = node.text

#after iterating i need to that change the node value
reference = 'hello world'

有没有办法在python中做到这一点?

谢谢!

1 个答案:

答案 0 :(得分:1)