A simple xml.dom.minidom question
Peter Otten
__peter__ at web.de
Fri May 7 05:17:50 EDT 2004
Paulo Pinto wrote:
> There are a set of applications that use XML files
> as their configuration mechanism. Inside these files
> there is some data that isn't standard XML but it in
> form expected by the tools.
>
> For example
>
> <values>
> "value1" "value2"
> </values>
>
> Now, if I use writexml(), I get the following,
>
> <values>
> "value1" "value2"
> </values>
>
> Which I understand, because it is how it should be
> in standard XML.
>
> However I am really required to use the first form.
Maybe you can get away with a tiny hack:
import xml.dom.minidom as md
import cStringIO
def wd(writer, data):
data = data.replace("&", "&").replace("<", "<")
writer.write(data)
md._write_data = wd
d = md.parseString("""<values>"v1" "v2"</values>""")
s = cStringIO.StringIO()
d.writexml(s)
print s.getvalue()
Peter
More information about the Python-list
mailing list