A simple xml.dom.minidom question

Paulo Pinto paulo.pinto at cern.ch
Fri May 7 05:55:26 EDT 2004


Thanks, that is what I ended up doing.

However it doesn't sound very clean, anyway it works
now. :)

Thanks everyone for your help
Paulo

Peter Otten wrote:
> 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