INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

xml.etree.ElementTree in python

xml.etree.ElementTree in python

(OP)
Hi,
i am new to xml parsing in python ,i used element tree and able to fetch data but mine is music player project that plays using the xml sheet

sample XML :

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Playlist>
<Playlist_ID>11414</Playlist_ID>
<Media_Id>428467</Media_Id>
<Media_Type>S</Media_Type>
<Airtime>11:00:00</Airtime>
<Title>TRACK 29</Title>
<Album>SINGLE</Album>
<Artists>, </Artists>
<FileName>428467.aac</FileName>
<Duration>00:02:06</Duration>
<NormalizationFactor>-6 db</NormalizationFactor>
</Playlist>
<Playlist>
<Playlist_ID>11414</Playlist_ID>
<Media_Id>428487</Media_Id>
<Media_Type>S</Media_Type>
<Airtime>11:02:07</Airtime>
<Title>TRACK 57</Title>
<Album>SINGLE</Album>
<Artists>, </Artists>
<FileName>428487.aac</FileName>
<Duration>00:01:44</Duration>
<NormalizationFactor>-6 db</NormalizationFactor>
</Playlist>
<Playlist>
<Playlist_ID>11414</Playlist_ID>
<Media_Id>428447</Media_Id>
<Media_Type>S</Media_Type>
<Airtime>11:03:52</Airtime>
<Title>TRACK 06</Title>
<Album>SINGLE</Album>
<Artists>, </Artists>
<FileName>428447.aac</FileName>
<Duration>00:07:27</Duration>
<NormalizationFactor>-6 db</NormalizationFactor>
</Playlist>
<Playlist>
<Playlist_ID>11414</Playlist_ID>
<Media_Id>428454</Media_Id>
<Media_Type>S</Media_Type>
<Airtime>11:11:20</Airtime>
<Title>TRACK 14</Title>
<Album>SINGLE</Album>
<Artists>, </Artists>
<FileName>428454.aac</FileName>
<Duration>00:02:10</Duration>
<NormalizationFactor>-6 db</NormalizationFactor>
</Playlist>
<Playlist>
<Playlist_ID>11414</Playlist_ID>
<Media_Id>428453</Media_Id>
<Media_Type>S</Media_Type>
<Airtime>11:13:31</Airtime>
<Title>TRACK 13</Title>
<Album>SINGLE</Album>
<Artists>, </Artists>
<FileName>428453.aac</FileName>
<Duration>00:02:52</Duration>
<NormalizationFactor>-6 db</NormalizationFactor>
</Playlist>
<Playlist>
<Playlist_ID>11414</Playlist_ID>
<Media_Id>428458</Media_Id>
<Media_Type>S</Media_Type>
<Airtime>11:16:24</Airtime>
<Title>TRACK 20</Title>
<Album>SINGLE</Album>
<Artists>, </Artists>
<FileName>428458.aac</FileName>
<Duration>00:02:11</Duration>
<NormalizationFactor>-6 db</NormalizationFactor>
</Playlist>
<Playlist>
<Playlist_ID>11414</Playlist_ID>
<Media_Id>428445</Media_Id>
<Media_Type>S</Media_Type>
<Airtime>11:18:36</Airtime>
<Title>TRACK 04</Title>
<Album>SINGLE</Album>
<Artists>, </Artists>
<FileName>428445.aac</FileName>
<Duration>00:05:14</Duration>
<NormalizationFactor>-6 db</NormalizationFactor>
</Playlist>
</newDataSet>

from this xml sheet the current system time has to be compared with the AIRTIME ,if it matches then grab the FILENAME and move to the particular folder where the file has saved and play...

i am able to get the Airtime and compare with system time like this:


>>> import xml.etree.ElementTree as ET
>>> import datetime
>>> now = datetime.datetime.now()
>>> td = now.strftime("%d-%m-%Y")
>>> tm = now.strftime("%H:%M:%S")
>>> path = 'C:/Users/dheedesk/Desktop/'
>>> newp = ''.join([path,td,'.xml'])
>>> tree = ET.parse(newp)
>>> root = tree.getroot()
for Airtime in root.iter("Airtime"):
if tm < Airtime:
print ""
elif tm == Airtime:
print ""
elif tm > Airtime:
print ""
else:
print ""

by this code i am getting the entire xml data,but i need only one time which is '<' or '=' to the current time and from that particular dataset it should grab the file name...
please.. help me on this, thank you.



Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close