Adding Comments To Xml Documents
Code: from lxml import etree # Create the network XML file tree root = etree.Element('network') tree = etree.ElementTree(root) # Create the nodes data name = etree.Element('nodes
Solution 1:
To insert a comment you can do this, after your code:
comment = etree.Comment(' === Some Comment === ')
root.insert(1, comment) # 1is the index where comment is inserted
If you want to add spaces, for instance in the tail of the nodes
element, that may mess with prettyprint, because once there is text in tails it won't know where to add whitespace safely. I suppose you could use the same technique as indent
, from ElementLib.
Post a Comment for "Adding Comments To Xml Documents"