Click here to Skip to main content
12,999,043 members (50,027 online)
Rate this:
Please Sign up or sign in to vote.
I am fairly new to programming and have doing well on my own but I could use help with this one.

I have an XML file that I want to pull NodeList[0].FirstChild.ChildNodes[4].InnerText from and fill my check the corresponding items in the CheckedListBox. Part of the challenge is that I am storing the values text in the XML and need to read it back in with the item numbers. In the case below the numbers would be 1,2.

Here are the listbox items:
Windows 7 SP1 (x64)
Windows 7 SP1 (x86)
Windows Vista SP2 (x64)
Windows Vista SP2 (x86)
Windows XP SP3 (x64)
Windows XP SP3 (x86)

using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml;

For reference, here is the code I am using to store the values in the XML file.
private void buttonSaveToXML_Click(object sender, EventArgs e)
    XmlWriterSettings settings = new XmlWriterSettings();
    settings.Indent = true;
    MemoryStream strm = new MemoryStream();
    XmlWriter XmlWrt = XmlWriter.Create("Releases_List2.xml", settings);
        if (checkedWindowsVersion.CheckedItems.Count != 0)
            //If so, loop through all checked items and print results.
            string s = "";
            for (int x = 0; x <= checkedWindowsVersion.CheckedItems.Count - 1; x++)
                s = s + checkedWindowsVersion.CheckedItems[x].ToString() + ",";
                XmlWrt.WriteElementString("WindowsVersion", s.TrimEnd(",".ToCharArray()));
            MessageBox.Show("Release List Updated");

Here is the relevant portion of the XML file:
<?xml version="1.0" encoding="utf-8" ?>
    <ReleaseName />
    <Date />
    <DetectedFile />
    <DetectedHash />
    <WindowsVersion>Windows 7 SP1 (x64),Windows 7 SP1 (x86)</WindowsVersion>

This is as close as I have come so far:
private void openToolStripMenuItem_Click(object sender, EventArgs e)
    openFileDialog1.Filter = "eXtendeble Markup Language (*.xml)|*.xml";
    openFileDialog1.FileName = "Releases_List.xml";
    if (openFileDialog1.ShowDialog() == DialogResult.OK)
        string path = openFileDialog1.FileName; //The Path to the .xml file
        FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //Set up the filestream
        XmlDocument Items = new XmlDocument(); //Set up the XmlDocument
        Items.Load(fs); //Load the data from the file into the XmlDocument
        XmlNodeList NodeList = Items.GetElementsByTagName("Releases_List"); //Create a list of the nodes in the xml file
        for (int i = 0; i < NodeList.Count; i++)
            //checkedWindowsVersion.CheckedItems = NodeList[0].FirstChild.ChildNodes[4].InnerText; //Supported OS's - MISSING CASES & CONVERSIONS
            checkedWindowsVersion.Items.AddRange(new object[]
			{ NodeList[0].FirstChild.ChildNodes[4].InnerText });

I would appreciate any help.
Posted 13-Jan-12 1:21am
Updated 16-Jan-12 21:36pm
Manisha Tambade 13-Jan-12 8:35am
I think ,
openFileDialog1.FileName = "Releases_List.xml";
here u should have write "Releases_List2.xml";
DCS78 13-Jan-12 19:55pm
Good eye! I will in the end product but for testing purposes I am opening one and writing to another. Eventually I will be reading in and writing out multiple items to/from the single XML file.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 17 Jan 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100