I'm going through the lxml tutorial and I have a question:
Here is the code:
>>> html = etree.Element("html")
>>> body = etree.SubElement(html, "body")
>>> body.text = "TEXT"
>>> etree.tostring(html)
b'<html><body>TEXT</body></html>'
#############LOOK!!!!!!!############
>>> br = etree.SubElement(body, "br")
>>> etree.tostring(html)
b'<html><body>TEXT<br/></body></html>'
#############END####################
>>> br.tail = "TAIL"
>>> etree.tostring(html)
b'<html><body>TEXT<br/>TAIL</body></html>'
As you can see, in the wrapped block, the instruction br = etree.SubElement(body, "br")
will only create a <br />
mark, and why is that?
Is br
a reserved word?
` is the [shorthand notation](http://www.w3.org/TR/xhtml1/#h-4.6) for the empty element `
`. Since `SubElement()` doesn't create *tags*, but *elements*, a complete element is what you get. – Lukas Graf Oct 19 '14 at 10:37
" for the result of "body" is "". So the difference is done by the `tostring` function, not the SubElement one? – VELVETDETH Oct 19 '14 at 10:51