Parse XML and populate in List Box

Posted by cedar715 on Stack Overflow See other posts from Stack Overflow or by cedar715
Published on 2010-05-11T04:38:01Z Indexed on 2010/05/11 4:44 UTC
Read the original article Hit count: 376

Filed under:
|
|
|
|

I've posted the same question here and I've also got couple of good answers as well. While I was trying the same answers, I was getting compilation errors. Later I got to know that we are using .NET 2.0 and our existing application has no references to LINQ files.

After searching in SO, i tried to figured out partly:

public partial class Item
    {
        public object CHK { get; set; }
        public int SEL { get; set; }
        public string VALUE { get; set; }
    }

Parsing:

        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<LISTBOX_ST>
             <item><CHK></CHK><SEL>00001</SEL><VALUE>val01</VALUE></item>
             <item><CHK></CHK><SEL>00002</SEL><VALUE>val02</VALUE></item>
             <item><CHK></CHK><SEL>00003</SEL><VALUE>val03</VALUE></item>
             <item><CHK></CHK><SEL>00004</SEL><VALUE>val04</VALUE></item>
             <item><CHK></CHK><SEL>00005</SEL><VALUE>val05</VALUE></item>
                   </LISTBOX_ST>");            
       List<Item> _lbList = new List<Item>();
       foreach (XmlNode node in doc.DocumentElement.ChildNodes)
        {
            string text = node.InnerText; //or loop through its children as well
            //HOW - TO - POPULATE THE ITEM OBJECT ??????
        }
       listBox1.DataSource = _lbList;
       listBox1.DisplayMember = "VALUE";
       listBox1.ValueMember = "SEL";

How to read two child nodes - SEL and VALUE of node and populate the same in the new Item DTO??

© Stack Overflow or respective owner

Related posts about c#

Related posts about Xml