Convert raw data to XML

Justin Ezequiel justin.mailinglists at gmail.com
Tue Jan 30 03:50:15 CET 2007


On Jan 30, 10:42 am, elrondru... at gmail.com wrote:
> For example the raw data is as follows
>
> <?xml version="1.0" ?><Blah><ABC><Id id="1"/><Description>SomeText </
> Description><Result>PassorFail</Result></ABC></Blah>
>
> without spaces or new lines. I need this to be written into an XML
> file as
>
> <?xml version="1.0" ?>
> <Blah>
>        <ABC>
>               <Id id="1"/>
>               <Description>
>                          SomeText
>               </Description>
>               <Result>
>                          PassorFail
>               </Result>
>       </ABC>
> </Blah>
>

raw = r'<?xml version="1.0" ?><Blah><ABC><Id id="1"/
><Description>SomeText </Description><Result>PassorFail</Result></
ABC></Blah>'
import xml.dom.ext
import xml.dom.minidom
doc = xml.dom.minidom.parseString(raw)
xml.dom.ext.PrettyPrint(doc)
<?xml version='1.0' encoding='UTF-8'?>
<Blah>
  <ABC>
    <Id id='1'/>
    <Description>SomeText </Description>
    <Result>PassorFail</Result>
  </ABC>
</Blah>





More information about the Python-list mailing list