CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009
    Posts
    3

    Need to parse itunes xml

    this is what i have now... i know its like... completely wrong... but...

    Code:
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(xml);
                    XmlNodeList items = doc.GetElementsByTagName("item");
                    foreach (XmlNode node in items)
                    {
                        string title = "", duration = "", description = "", date = "", thumbnail = "", url = "";
                        foreach (XmlNode child in node.ChildNodes)
                        {
                            switch (child.Name)
                            {
                                case "title":
                                    title = child.InnerText;
                                    break;
                                case "description":
                                    description = child.InnerText;
                                    break;
                                case "url":
                                    XmlNode contentNode = null;
                                    contentNode = node.Attributes("enclosure", doc.GetElementsByTagName("item"));
                                    url = contentNode.Attributes["url"].Value;     
                                    break;
                                case "thumbnail":
                                    thumbnail = child.InnerText;
                                    break;
                                case "duration":
                                    // required format is "H:MM:SS"
                                    TimeSpan ts = TimeSpan.FromMilliseconds(double.Parse(child.InnerText));
                                    duration = ts.Hours + ":" + ts.Minutes.ToString("D2") + ":" + ts.Seconds.ToString("D2");
                                    break;
                                case "pubDate":
                                    // required format is "2008-04-10T06:30:00"
                                    date = DateTime.Parse(child.InnerText, System.Globalization.CultureInfo.InvariantCulture).ToString("s");
                                    break;
                            }
                        }
    and this is what i need to parse

    Code:
    <item>
    			<title>Love Bites - Sea of Love</title>
    			<itunes:author>Happy Tree Friends</itunes:author>
    
    			<description>If this boats a-rockin dont come a-knockin! Watch the second Love Bites short, Sea Of Love and prepare to fall in love all over again!</description>
    			<itunes:subtitle>If this boats a-rockin dont come a-knockin! Watch the second Love Bites short, Sea Of Love and prepare to fall in love all over again!</itunes:subtitle>
    			<itunes:summary>If this boats a-rockin dont come a-knockin! Watch the second Love Bites short, Sea Of Love and prepare to fall in love all over again!</itunes:summary>
    			<category>Comedy</category>
    			<itunes:keywords>Cartoons, Animation</itunes:keywords>
    			<itunes:image href="http://podcast.happytreefriends.com/htf.jpg"/>
    
    			<itunes:explicit>yes</itunes:explicit>
    			<enclosure url="http://media.libsyn.com/media/mondomedia/HTF_LB_SeaOfLove.m4v" length="7102660" type="video/mpeg"/>
    			<itunes:duration>1:30</itunes:duration>
    			<guid>http://media.libsyn.com/media/mondomedia/HTF_LB_SeaOfLove.m4v</guid>
    			<pubDate>Fri, 13 Feb 2009 12:00:00 -0800</pubDate>
    		</item>
    basicly need the case "url" to equal the enclosure url also need the case "duration" to read the enclosure length... this is a bit over my head..

  2. #2
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Need to parse itunes xml

    What happens if you do

    DataSets ds = new DataSet()
    ds.ReadXml("path to itunes xml")


    Or have you tried using XSD.exe to infer a schema and create you some stub classes?
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured