replacing string in xml file

Stefan Behnel stefan.behnel-n05pAM at web.de
Tue May 8 07:30:59 EDT 2007


saif.shakeel 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



More information about the Python-list mailing list