Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6985525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:41:29+00:00 2026-05-27T18:41:29+00:00

I know this will look like a stupid simple question to ask but I

  • 0

I know this will look like a stupid simple question to ask but I will ask it anyways. I have been trying to read this xml file:

<Songs>
<song>
  <TrackID>1666</TrackID>
  <Name>What's the Matter Here?</Name>
  <Artist>10,000 Maniacs</Artist>
  <AlbumArtist>10,000 Maniacs</AlbumArtist>
  <Composer>Natalie Merchant/Robert Buck</Composer>
  <Album>In My Tribe</Album>
  <Genre>Rock</Genre>
  <Kind>MPEG audio file</Kind>
  <Size>9318485</Size>
  <TotalTime>291134</TotalTime>
  <TrackNumber>1</TrackNumber>
  <Year>1987</Year>
  <DateModified>2005-03-09T07:31:09Z</DateModified>
  <DateAdded>2007-07-20T17:21:36Z</DateAdded>
  <BitRate>256</BitRate>
  <SampleRate>44100</SampleRate>
  <Comments> </Comments>
  <PersistentID>54F22391EB807F38</PersistentID>
  <TrackType>File</TrackType>
  <Location></Location>      
</song>
<song>
  <TrackID>1666</TrackID>
  <Name>What's the Matter Here?</Name>
  <Artist>10,000 Maniacs</Artist>
  <AlbumArtist>10,000 Maniacs</AlbumArtist>
  <Composer>Natalie Merchant/Robert Buck</Composer>
  <Album>In My Tribe</Album>
  <Genre>Rock</Genre>
  <Kind>MPEG audio file</Kind>
  <Size>9318485</Size>
  <TotalTime>291134</TotalTime>
  <TrackNumber>1</TrackNumber>
  <Year>1987</Year>
  <DateModified>2005-03-09T07:31:09Z</DateModified>
  <DateAdded>2007-07-20T17:21:36Z</DateAdded>
  <BitRate>256</BitRate>
  <SampleRate>44100</SampleRate>
  <Comments> </Comments>
  <PersistentID>54F22391EB807F38</PersistentID>
  <TrackType>File</TrackType>
  <Location></Location>      
</song>
</Songs>

I am using this code to read the above:

    private static void LoadSongsFromITunes(string xmlFile)
    {
        XmlReaderSettings settings = new XmlReaderSettings();
        settings.IgnoreComments = true;
        settings.IgnoreWhitespace = true;
        string album=null ;
        string artists=null ;
        string genres=null ;
        string  year=null ;
        string duration=null ;

        try
        {
            using (XmlReader reader = XmlReader.Create(xmlFile, settings))
            {
                string xmlContent;

                while (reader.Read())
                {
                    if (reader.NodeType != XmlNodeType.Element) continue;
                    xmlContent = "";
                    string name=null;
                    if (reader.Name == "Name")
                    {
                        name = reader.ReadString().ToString();
                    }
                    if (reader.Name == "Artist")
                    {
                        artists = reader.ReadString().ToString();
                    }
                    if (reader.Name == "Album")
                    {
                        album = reader.ReadString().ToString();
                    }
                    if (reader.Name == "Genre")
                    {
                        genres = reader.ReadString().ToString();
                    }
                    if (reader.Name == "Year")
                    {
                        year = reader.ReadString();
                    }
                    if (reader.Name == "Duration")
                    {
                        duration  = reader.ReadString().ToString();
                    }
                    Console.WriteLine(name);
                }
            }
        }
        catch
        {

        }

However, it seems like the reader just returns null. I have stepped over the code through the debugger but I can’t quite get what’s wrong with this code.
P.S: Can someone provide a better way to do this? Like using link to xml or something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:41:30+00:00Added an answer on May 27, 2026 at 6:41 pm

    LINQ to XML:

    var doc = XDocument.Parse(xml);
    
    var result = doc
        .Root.Elements("song")
        .Select(e => 
            new { Name = (string)e.Element("Name"), Artist = (string)e.Element("Artist") });
    
    foreach (var val in result)
    {
        Console.WriteLine(val);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Know this might be rather basic, but I been trying to figure out how
I know this isn't strictly a programming question but y'all must have experienced this.
I know this question may be lame, but I'm trying to find a list
I know this very regular question But i didn't get that's way ask here
I know this will be a difficult question, so I am not necessarily looking
I know that this feature will be deprecated in C++0x, but for me as
I know downcasting like this won't work. I need a method that WILL work.
I know this might be a no-brainer, but please read on. I also know
The question plot (a bit abstract, but answering this question will help me in
I'm trying to select some data from another query. The SQL will look like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.