CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: read xml files

  1. #1
    Join Date
    Sep 2004
    Posts
    8

    read xml files

    Hi
    I need to know how i can to read a xml file with the structure
    I need a loop for to do this
    but Anybody know the method?
    My xml file
    <configuration>
    <appSettings>
    <add key="key1" value="value1"/>
    <add key="key2" value="value2"/>
    <add key="key3" value="value3"/>
    </appSettings>
    </configuration>

    i need to introduce "key1".... "keyn" and "value1"..."valuen" in a structura SortedList sl = new SortedList()
    sl.Add(key,value)

    Thanks very much

  2. #2
    Join Date
    Nov 2003
    Location
    Sweden
    Posts
    129

    Re: read xml files

    Why dobnt you just use something like XML Reader that could be found in System.XML nnameespace??
    I will post a code for you as soon as i get home... it will bee in 3-4 hours...
    Regards,
    Alexei

  3. #3
    Join Date
    Mar 2002
    Posts
    109

    Re: read xml files

    If you are loading from a config file, then you don't need to use the XmlReader, it's already loaded into your Configuration.AppSettings collection, below is how you access it:

    System.Configuration.ConfigurationSettings.AppSettings["key1"]
    System.Configuration.ConfigurationSettings.AppSettings["key2"]

    If you need to loop through it, just loop through the AppSettings collection.

    Also, just in case you are not aware of this, but the xml config file must be named a certain way: YourAppNameHere.exe.config. If you need the code to iterate through the collection, I can post it. Hope this helps.

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