对 lxml 节点的引用
我正在迭代从 xpath 查询中获得的 xml 节点值。我需要分配对某个节点值的引用。
我想要的是:
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 中做到这一点?
谢谢!
i'm iterating xml node values, which i get from xpath query. And i need to assign a reference to some node value.
Here what i want to to:
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'
is there a way to do it in python?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
相反,存储对实际节点的引用:
store a reference to the actual node instead: