etree

etree.findall: 'OR'-lookup?

I want to find all stylesheet definitions in a XHTML file with lxml.etree.findall. This could be as simple as elems = tree.findall('link[@rel="stylesheet"]') + tree.findall('style') But the problem with CSS style definitions is that the order matters, e.g. <link rel="stylesheet" type="text/css" href="/media/css/first.css" /> <style>b...

how to remove attribute of a etree Element ?

I've Element of etree having some attributes - how can we delete the attribute of perticular etree Element. ...

how to find recursively for a tag of xml using LXML ?

using lxml is it possible to find recursively for tag " f1 ", i tried findall method but it works only for immediate children. I think I should go for BeautifulSoup for this !!! ...

How to prevent lxml prom compacting elements?

Having following Python code: >>> from lxml import etree >>> root = etree.XML("<a><b></b></a>") >>> etree.tostring(root) '<a><b/></a>' How can I force lxml to use "long" version? Like >>> etree.tostring(root) '<a><b></b></a>' ...

creating xml tree from a textfile with Python

Hi, I need to avoid creating double branches in an xml tree when parsing a text file. Let's say the textfile is as follows (the order of lines is random): branch1:branch11:message11 branch1:branch12:message12 branch2:branch21:message21 branch2:branch22:message22 So the resulting xml tree should have a root with two branches. Both of th...