Problem loading XML Document in C# .NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JustinLee
    New Member
    • Feb 2008
    • 1

    Problem loading XML Document in C# .NET

    Hi,
    I have a small app that saves and loads data in XML format. Basically I have 2 methods. They each load data from a different XML documents. They both load data the same way. Everything works great except if I call method 1, then method 2, then method 1 again. When I call method 1 the second time, and the XmlDocument is loaded, it is missing a whole level of nodes. I put a break point on the XmlDocument right after the xmlDoc.Load() is called, and its not showing all the nodes that are in the document.

    Code:
    private void MethodOne()
    {
       XmlDocument xmlDoc = new XmlDocument();
       xmlDoc.Load("AllSongs.xml");
       XmlNodeList songs = xmlDoc.SelectNodes("Songs/Song");
       foreach (XmlNode node in songs)
       {     
          // create Song object and add to ArrayList             
       }
       //Display ArrayList of Songs
    }
    Method 2 is basically the same except it opens a different xml file. I can call method 1 many times and it works great. But once I call method 2, method 1 stops working. (The XmlNodeList "songs" above contains no nodes). "xmlDoc" only contains the first node. The actual file does not get altered. If I restart the app, Method 1 works correctly again, and loads all the nodes.

    Any ideas?
    Thanks
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    Could you paste some code on how you call the 2 methods?

    Also check if the second xml file that you are talking abt is a valid xml file.
    i.e with corect tags and an xml definition

    Comment

    Working...