By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,846 Members | 1,857 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,846 IT Pros & Developers. It's quick & easy.

Element tree errors

P: n/a
HI,
The following code is for replacing the strings localid with
"datapackageid" in an xml document.:

from xml.etree.ElementTree import ElementTree as et

file_input = raw_input("Enter The ODX File Path:")
(shortname,ext)=os.path.splitext(file_input)
test_file=shortname+"testxml.xml"

input_xml = open(file_input,'r')

tree = et.parse(input_xml)

for t in tree.getiterator("SERVICEPARAMETER"):
if t.get("Semantics") == "localId":
t.set("Semantics", "dataPackageID")

tree.write(test_file)

The python ver is 2.5.there is no module error
now,but when i run i get this error:

Traceback (most recent call last):
File "C:\Documents and Settings\pzchfr\Desktop\test.py", line 12, in
<module>
tree = et.parse(input_xml)
TypeError: unbound method parse() must be called with ElementTree
instance as first argument (got file instance instead)

I am passing the input file from user to be parsed
which seems to be incorrect,Can someone help me.
Thanks

May 14 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On May 14, 7:56 pm, saif.shak...@gmail.com wrote:
HI,
The following code is for replacing the strings localid with
"datapackageid" in an xml document.:

from xml.etree.ElementTree import ElementTree as et
Note there are *two* occurrences of ElementTree in what you have
above. The first is the *module* with the parse function that that you
are looking for. The second is a *class*.

Try this:

import xml.etree.ElementTree as et
input_xml = open(file_input,'r')
tree = et.parse(input_xml)

or this:

from xml.etree.ElementTree import parse
input_xml = open(file_input,'r')
tree = parse(input_xml)


May 14 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.