Is it possible to somehow create element with default text value? So I would not need to do it like this?
from lxml import etree
root = etree.Element('root')
a = etree.SubElement(root, 'a')
a.text = 'some text' # Avoid this extra step?
I mean you can specify attributes in SubElement, but I don't see a way to specify text in it.
lxml is a reference to the XML toolkit in a pythonic way which is internally being bound with two specific libraries of C language, libxml2, and libxslt. lxml is unique in a way that it combines the speed and XML feature completeness of these libraries with the simplicity of a native Python API.
lxml has been downloaded from the Python Package Index millions of times and is also available directly in many package distributions, e.g. for Linux or macOS.
How about the following?
etree.SubElement(root, "a").text = "some text"
Works only if you do not need to assign the resultant element to a variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With