Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Element tree errors

Reply
Thread Tools

Element tree errors

 
 
saif.shakeel@gmail.com
Guest
Posts: n/a
 
      05-14-2007
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

 
Reply With Quote
 
 
 
 
John Machin
Guest
Posts: n/a
 
      05-14-2007
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)




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
B+ Tree versus Ternary Search Tree Ramkumar Menon Java 2 08-16-2005 08:13 PM
Errors, errors, errors Mark Goldin ASP .Net 2 01-17-2004 08:05 PM
B tree, B+ tree and B* tree Stub C Programming 3 11-12-2003 01:51 PM
Spanning Tree And Per Vlan Spanning Tree Amy L. Cisco 0 07-24-2003 10:01 PM



Advertisments