Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have Problem Reading XML and using dictionary to store all tags and their values.I have used this code in VB.Net without problem. It fails while "adding the tag as the key and the tag's value as the value"

C#
public class ConfigReader {
   IDictionary dict;
  
    public LoginConfigReader()
    {
        dict = new SortedList();

        string myXmlFile = null;
        myXmlFile = HostingEnvironment.ApplicationPhysicalPath + "App_Data\\myxmlfile.xml";

       
        XmlTextReader reader = new XmlTextReader(myXmlFile);
        reader.WhitespaceHandling = WhitespaceHandling.None;
       
        reader.Read();        // read the config tag
        reader.Read();        // go to the first tag

       
        while ((!reader.EOF))
        {
            if (!reader.IsStartElement())
            {
                break; 
            }

        dict.Add(reader.Name, reader.ReadElementString); // add the tag as the key and the tag's value as the value
            

        }
        reader.Close(); //close the reader
    }
Posted

1 solution

Lots of options.[^]. You should always attempt a search on google of your question. The search "How to read Xml Document C# to dictionary" returned 1.58 million results. The first page is full of potential solutions for you. Cheers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900