Click here to Skip to main content
Rate this: bad
good
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:
ANY
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);
 
    try
    {
        XmlWrt.WriteStartDocument();
        XmlWrt.WriteStartElement("Releases_List");
        XmlWrt.WriteStartElement("Item");
 
        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()));
            }
 
            XmlWrt.WriteEndElement();
            XmlWrt.WriteEndDocument();
            XmlWrt.Flush();
            XmlWrt.Close();
 
            MessageBox.Show("Release List Updated");
        }
        catch
        {
            throw;
        }
    }
}	
 
Here is the relevant portion of the XML file:
<?xml version="1.0" encoding="utf-8" ?>
<Releases_List>
  <Item>
    <ReleaseName />
    <Date />
    <DetectedFile />
    <DetectedHash />
    <WindowsVersion>Windows 7 SP1 (x64),Windows 7 SP1 (x86)</WindowsVersion>
  </Item>
</Releases_List>
 
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
DCS78407
Edited 16-Jan-12 21:36pm
v4
Comments
Manisha Tambade at 13-Jan-12 8:35am
   
I think , openFileDialog1.FileName = "Releases_List.xml"; here u should have write "Releases_List2.xml";
DCS78 at 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
0 Sergey Alexandrovich Kryukov 716
1 OriginalGriff 442
2 Tadit Dash 400
3 sanket saxena 337
4 Peter Leow 228
0 Sergey Alexandrovich Kryukov 11,890
1 OriginalGriff 7,335
2 Peter Leow 5,003
3 Abhinav S 3,943
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web03 | 2.8.140421.2 | Last Updated 17 Jan 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid