replacing string in xml file

saif.shakeel at gmail.com saif.shakeel at gmail.com
Tue May 8 07:23:34 EDT 2007


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')
input_xml.replace('localId','dataPackageId')
                     This gives error  ---> AttributeError: 'file'
object has no attribute 'replace'
        Can someone help me .
                  Thanks




More information about the Python-list mailing list