Would like to write raw string """ to value of an attribute.
using python minidom!
After writing """ to XML file ,it looks like "&quot" in the file.
pls help me on this....
Would like to write raw string """ to value of an attribute.
using python minidom!
After writing """ to XML file ,it looks like "&quot" in the file.
pls help me on this....
Use the regular double quote character in the string value of the attribute. The code will take care of converting it to "
in the XML output.
Here's an example. First, create the document:
In [52]: from xml.dom.minidom import getDOMImplementation
In [53]: impl = getDOMImplementation()
In [54]: doc = impl.createDocument(None, "tag", None)
In [55]: top_element = doc.documentElement
Set the "foo" attribute of the top element. Note that there are double quotes in the string that will be the value of the "foo" attribute.
In [56]: top_element.setAttribute("foo", '"plate of shrimp"')
When the document is printed, those double quotes are converted to "
:
In [57]: print(top_element.toprettyxml())
<tag foo=""plate of shrimp""/>