xml tags in a list

This is the place for queries that don't fit in any of the other categories.

xml tags in a list

Postby bajaj » Wed May 29, 2013 7:04 pm

My xml file is like this
Code: Select all
<feed text='11' r_version='abc'>
       <title>Dive into history, 2009 edition</title> 
       <link rel='alternate' type='text/html'  href='aa'/> 
       <category scheme='bb' term='diveintopython'/>   
       <category scheme='b1' term='docbook'/>   
       <category scheme='b2' term='html'/>
       <summary type='html'>some text</summary>
        <summary type='html'>some other text.</summary>

what I am trying to do is read this xml file using ElementTree and save it in the list. I am getting that result but the list braket are wrong.

Code: Select all
tree =ET.parse(my.xml)
   for elem in tree.iter():   

Code: Select all
[["feed", {"text": "11", "r_version": "abc"}], ["entry", {}], ["author", {}], ["name", {}], ["uri", {}], ["title", {}], ["link", {"href": "aa", "type": "text/html", "rel": "alternate"}], ["id", {}], ["updated", {}], ["published", {}], ["category", {"term": "diveintopython", "scheme": "bb"}], ["category", {"term": "docbook", "scheme": "b1"}], ["category", {"term": "html", "scheme": "b2"}], ["summary", {"type": "html"}], ["entry", {}], ["author", {}], ["name", {}], ["uri", {}], ["summary", {"type": "html"}]]

since feed tag start at first and end at last so the result should be like same with the entry tag

Code: Select all
[[["feed", {"text": "11", "r_version": "abc"}], ["entry", {}], ["author", {}], ["name", {}], ["uri", {}], ["title", {}], ["link", {"href": "aa", "type": "text/html", "rel": "alternate"}], ["id", {}], ["updated", {}], ["published", {}], ["category", {"term": "diveintopython", "scheme": "bb"}], ["category", {"term": "docbook", "scheme": "b1"}], ["category", {"term": "html", "scheme": "b2"}], ["summary", {"type": "html"}], ["entry", {}], ["author", {}], ["name", {}], ["uri", {}], ["summary", {"type": "html"}]] ]

I need help to achive this.

Last edited by stranac on Wed May 29, 2013 7:09 pm, edited 1 time in total.
Reason: Added code tags
Posts: 2
Joined: Wed May 29, 2013 6:41 pm

Re: xml tags in a list

Postby MichelFJM » Thu May 30, 2013 2:12 pm

You should be more clear with what you want, give the correct output (the second given has only one [] more : it is probably not yet correct) and give a working python program.
Posts: 19
Joined: Wed May 22, 2013 1:41 pm

Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 9 guests