Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't read a simple xml file
    primarykey
    data
    text
    <p>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: </p> <pre><code>&lt;Songs&gt; &lt;song&gt; &lt;TrackID&gt;1666&lt;/TrackID&gt; &lt;Name&gt;What's the Matter Here?&lt;/Name&gt; &lt;Artist&gt;10,000 Maniacs&lt;/Artist&gt; &lt;AlbumArtist&gt;10,000 Maniacs&lt;/AlbumArtist&gt; &lt;Composer&gt;Natalie Merchant/Robert Buck&lt;/Composer&gt; &lt;Album&gt;In My Tribe&lt;/Album&gt; &lt;Genre&gt;Rock&lt;/Genre&gt; &lt;Kind&gt;MPEG audio file&lt;/Kind&gt; &lt;Size&gt;9318485&lt;/Size&gt; &lt;TotalTime&gt;291134&lt;/TotalTime&gt; &lt;TrackNumber&gt;1&lt;/TrackNumber&gt; &lt;Year&gt;1987&lt;/Year&gt; &lt;DateModified&gt;2005-03-09T07:31:09Z&lt;/DateModified&gt; &lt;DateAdded&gt;2007-07-20T17:21:36Z&lt;/DateAdded&gt; &lt;BitRate&gt;256&lt;/BitRate&gt; &lt;SampleRate&gt;44100&lt;/SampleRate&gt; &lt;Comments&gt; &lt;/Comments&gt; &lt;PersistentID&gt;54F22391EB807F38&lt;/PersistentID&gt; &lt;TrackType&gt;File&lt;/TrackType&gt; &lt;Location&gt;&lt;/Location&gt; &lt;/song&gt; &lt;song&gt; &lt;TrackID&gt;1666&lt;/TrackID&gt; &lt;Name&gt;What's the Matter Here?&lt;/Name&gt; &lt;Artist&gt;10,000 Maniacs&lt;/Artist&gt; &lt;AlbumArtist&gt;10,000 Maniacs&lt;/AlbumArtist&gt; &lt;Composer&gt;Natalie Merchant/Robert Buck&lt;/Composer&gt; &lt;Album&gt;In My Tribe&lt;/Album&gt; &lt;Genre&gt;Rock&lt;/Genre&gt; &lt;Kind&gt;MPEG audio file&lt;/Kind&gt; &lt;Size&gt;9318485&lt;/Size&gt; &lt;TotalTime&gt;291134&lt;/TotalTime&gt; &lt;TrackNumber&gt;1&lt;/TrackNumber&gt; &lt;Year&gt;1987&lt;/Year&gt; &lt;DateModified&gt;2005-03-09T07:31:09Z&lt;/DateModified&gt; &lt;DateAdded&gt;2007-07-20T17:21:36Z&lt;/DateAdded&gt; &lt;BitRate&gt;256&lt;/BitRate&gt; &lt;SampleRate&gt;44100&lt;/SampleRate&gt; &lt;Comments&gt; &lt;/Comments&gt; &lt;PersistentID&gt;54F22391EB807F38&lt;/PersistentID&gt; &lt;TrackType&gt;File&lt;/TrackType&gt; &lt;Location&gt;&lt;/Location&gt; &lt;/song&gt; &lt;/Songs&gt; </code></pre> <p>I am using this code to read the above:</p> <pre><code> 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 { } </code></pre> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload