[lxml-dev] DOM tree intersection/comparison?
Viksit Gaur
vik.list.nutch at gmail.com
Tue May 27 09:34:09 CEST 2008
Hey,
Stefan Behnel wrote:
> Stefan Behnel wrote:
>
> I added a simple BFS recipe to the iteration section of api.txt:
Oh thats a neat way of doing it. I didn't know about deque - was using
lists and pops! Thanks for the pointer..
Cheers,
Viksit
>
> >>> root = etree.XML('<root><a><b/><c/></a><d><e/></d></root>')
> >>> print(etree.tostring(root, pretty_print=True, encoding=unicode))
> <root>
> <a>
> <b/>
> <c/>
> </a>
> <d>
> <e/>
> </d>
> </root>
>
> >>> queue = deque([root])
> >>> while queue:
> ... el = queue.popleft() # pop next element
> ... queue.extend(el) # append its children
> ... print(el.tag)
> root
> a
> d
> b
> c
> e
>
>
> Stefan
>
>
>
More information about the lxml-dev
mailing list