populate dropdownlist from xml file

I have created a simple xml file that includes a small list of values to populate a dropdown list.  I can map to the xml file read the data in the xml file and bind it to the dropdownlist.

Here is my question.  I have a class library that I have created a dataset (.xsd) file with tableadapters that make calls to the database.

So, is there a way to add the dataset that pulls info from my xml file into the dataset in my class library?

I'm not sure how to do this?  I want to keep all the data extraction seperate from the application.  The way I have it now is the page code-behind:

protected void BindList()
        string path = MapPath("~/products.xml");
        DataSet dSet = new DataSet();

        chklst.DataSource = dSet;
        chklst.DataTextField = "name";
        chklst.DataValueField = "productid";

Is it possible to move the dataset portion into the class library?  If so, how?

Basically, what I'd like to have in the code-behind is the following:

GetEmployeeTableAdapter employee = new GetEmployeeTableAdapter();
ddlEmployee.DataSource = employee.GetEmployee();
ddlEmployee.DataTextField = "customer_id";
ddlEmployee.DataValueField = "recordID";
ddlEmployee.Items.Insert(0, new ListItem("Please select...", ""));

I just don't know how to create the dataset in the class library that reads from the xml.  The table adapters only seem to connect to a database.

Is what I want to accomplish possible?

Thanks for any help.
Who is Participating?
Sachintana DissanayakeConnect With a Mentor Senior Web DeveloperCommented:
I think you need to create a bounded Dataset, by looking at the XML file which is mapped to the existing .net classes. You need to keep the mapping in a XSD schema file. You can use the same xsd tool to generate the xsd schema from existing .net class library (dll or exe).
   xsd assemblyName.dll will generate a XSD schema.

In nHibernate, you have to define the database schema in a XML, not data.
But there;s another framework called ODX (Open Dataset eXtensions) - http://www.codeplex.com/odx
It supports XML data sources as well. I haven't use this, you need to research on this little more...
Sachintana DissanayakeSenior Web DeveloperCommented:
You can use xsd to class generation command line tool and it will generate .cs classes for your xsd.
     eg. xsd.exe "schemefile.xsd" /classes

If you are looking for a solution for your whole project, you can use nHibernate to map database objects to classes. It will automatically generate .net classes by accessing the database tables.
-Dman100-Author Commented:
Hi sachintana,
Thanks for replying to my post.  My apologies, I got a little lost on your post.  I've never used the xsd to class generation tool

I might be misuderstanding, but after thinking about it further, can I not add a new class to my library project, add the xml file, create a method that creates the dataset and reads the xml data, recompile, add the reference to my web project and then simply call the method to bind the dropdownlist with the xml data?

I've heard about nHibernate, but have never used that either.  Does that work with xml files as well as databases?

Sorry for the novice questions.

I appreciate the help.  thank you.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.