Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 4th, 2006, 03:24 AM
Registered User
 
Join Date: Oct 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Read data from XML then load it into combo box

Hi all,

This is my first post in this forum, hope can get some helps and guides from you all..:)
My question sound like this:

I'm currently develop a window base applicationin c#. So far, I had create a xml files and plan to load the data into combo box accordingly base on the node name, example:

a) Sample of XML files:
**********************************************
  <Material>
    <C>Ceramic</C>
    <L>Glass</L>
  </Material>
  <Position>
    <A>Axial</A>
    <B>Bottom</B>
    <D>Dual</D>
  </Position>
***********************************************

So, there will be two different combo box, one to store 'Material' and the other one to store 'Position', i want the data such as Ceramic, glass load into first combo box, and data such as "Axial", "Bottom" into second combo box,
how can i do that.

I used XML TextReader but seem like i can't specify which node to load, the code will give me the whole things(ceramic, glass, axial, bottom, dual), here is the code i used:

*************************************************
xtr = new XmlTextReader(fileName);
xtr.WhitespaceHandling = WhitespaceHandling.None;

while (xtr.Read())
{
switch (xtr.NodeType)
{
case XmlNodeType.Text: this.cboMaterial.Items.Add(xtr.Value);
break;

}
}
************************************************** *


Any help is appreciated, please help.
Thank you.
 
Old October 4th, 2006, 03:41 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

XmlTextReader is a very low-level interface to be using for this application. I would write it in XSLT, or if you must use C#, read the document into a DOM (XmlDocument) and then proceed by navigating the DOM.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 4th, 2006, 04:24 AM
Registered User
 
Join Date: Oct 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, thanks for your reply mhkay,
but can you elaborate more? since i'm really new in XML. What is XSLT actually? i try DOM before but cant figure out how to do that, can you show me the sample how to get it done?
Thanks..:)

 
Old October 4th, 2006, 05:04 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Do you mean a combobox or a listbox? I've used XML binding on the latter, the former is different so you may need to experiment.
You can bind to a nodeset using code like:
Code:
nodeList = xDoc.SelectNodes("/Countries/country") 
        lstCountries.DataTextField = "InnerText" 
        lstCountries.DataValueField = "InnerText" 
        lstCountries.DataSource = nodeList 
        lstCountries.DataBind();
This works when you have an XML such as:
Code:
<countries>
<country>England</country>
<country>Scotland</country>
<country>Wales</country>
</countries>
The trouble with your XML is its shape, and it has no document element shown. What's the significance of <C> as opposed to <L> for example? You might get to work with /*/Material/* and /*/Position/* but I'm not sure.

--

Joe (Microsoft MVP - XML)
 
Old October 4th, 2006, 05:11 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sorry, your questions are too big, and the answers have all been written before in countless books and magazine articles. You need to spend a little time reading, and then come back here if you have more specific questions.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Filtering Data from one Combo Box to another Steve1977 ASP.NET 3.5 Basics 1 September 14th, 2008 08:50 AM
Rebinding a data to combo box zaki79 .NET Framework 1.x 2 April 25th, 2008 04:43 AM
Access Data from a combo box darkhalf Access VBA 1 February 22nd, 2008 04:28 PM
Inserting data from combo box bergs77 XSLT 0 January 3rd, 2006 01:09 PM
Combo Box - Data In Use MrDannyP Beginning VB 6 1 November 15th, 2003 10:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.