replacing string in xml file

saif.shakeel at gmail.com saif.shakeel at gmail.com
Tue May 8 07:46:10 EDT 2007


On May 8, 4:30 pm, Stefan Behnel <stefan.behnel-n05... at web.de> wrote:
> saif.shak... at gmail.com schrieb:
>
>
>
>
>
> > Hi,
> >      I need to replace a string in xml file with something else.Ex
>
> > - <SERVICEPARAMETER id="_775" Semantics="subfunction" DDORef="_54">
> >   <SHORTNAME>rate</SHORTNAME>
> >   <LONGNAME>rate</LONGNAME>
> >   <VALUE role="constant" DataType="unsigned" value="1" />
> >   <BYTEPOSITION role="position" BytePos="1" />
> >   </SERVICEPARAMETER>
> > - <SERVICEPARAMETER id="_776" Semantics="localId" DDORef="_54">
>
> >                                      Here i have opened an xml
> > file(small part is pasted here).I want to replace the word 'localId'
> > with 'dataPackageID' wherever it comes in xml file.I tried this but
> > didnt work:
>
> > import sys
>
> > file_input = raw_input("Enter The ODX File Path:")
> > input_xml = open(file_input,'r')
>
> This should say
>
>   input_xml = open(file_input,'r').read()
>
> > input_xml.replace('localId','dataPackageId')
> >                      This gives error  ---> AttributeError: 'file'
> > object has no attribute 'replace'
> >         Can someone help me .
> >                   Thanks
>
> Stefan- Hide quoted text -
>
> - Show quoted text -

There is no error now,but the string is not being replaced,It remains
the same,should we save the opened file or something




More information about the Python-list mailing list