Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在XML元素树[Py3]中重新/存储节点位置_Python_Xml_Elementtree - Fatal编程技术网

Python 在XML元素树[Py3]中重新/存储节点位置

Python 在XML元素树[Py3]中重新/存储节点位置,python,xml,elementtree,Python,Xml,Elementtree,在Python3 ElementTree中,如何存储XML节点位置,然后将其还原以继续从该位置进行遍历?(在XML树中等待异步用户输入) 节点对象有一个地址,我可以保存它然后恢复它吗,就像C指针一样 <Element 'entry' at 0x00000000026C4D68> 也许您可以使用root.iter(),它创建了一个迭代器。如果我能将位置存储在cookie中就好了,即基于文本的。我不知道是否可以将位置存储为文本cookie。但是迭代器会自动跟踪位置。 # parse X

在Python3 ElementTree中,如何存储XML节点位置,然后将其还原以继续从该位置进行遍历?(在XML树中等待异步用户输入)

节点对象有一个地址,我可以保存它然后恢复它吗,就像C指针一样

<Element 'entry' at 0x00000000026C4D68>

也许您可以使用
root.iter()
,它创建了一个迭代器。如果我能将位置存储在cookie中就好了,即基于文本的。我不知道是否可以将位置存储为文本cookie。但是迭代器会自动跟踪位置。
# parse XML
import xml.etree.ElementTree as ET
tree = ET.parse('tree.xml')
root = tree.getroot()

# start traversing
for child in root:
  # after few iterations need to abort traversing, save current node
  save(child)
  break

# later on I need to restore the node where I stopped
previousNode = restore()

# continue from the restored node downwards
for child in previousNode:
  pass