Using XMl as a database/databinding

How can i use xml as databinding

Page 1 of 1

2 Replies - 1558 Views - Last Post: 11 March 2009 - 11:02 PM Rate Topic: -----

#1 Tempus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-March 09

Using XMl as a database/databinding

Posted 10 March 2009 - 06:51 AM

Ok hope i get the protocol right here :-)

I'm trying to design a form/electronic character sheet for a rpg i play(world of darkness for the curious)

I have the mian sheet done no problem, but have hit a snag.

What i trying to do is have a drop down/combo box on the left side. In there is a list of spells/abilitys that is populated from a XML file(trying to avoid database as much as possible)

each, well "entry" in the xml file is like this
<name>"Death blast"</name>
<power>4</power>
<location>book 1 page 65</location>



As the user scrolls down this list, the spell name and associated atributes(such as power, size etc) are displayed in approriate box.

eg
[spell name ] (this is the combo box) [power][location] (changes depending on what is selected in name box)

I'm trying to find out if what i'm trying to acheive is possible with xml/data binding, or am i thinking up the wrong tree here?

Is This A Good Question/Topic? 0
  • +

Replies To: Using XMl as a database/databinding

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Using XMl as a database/databinding

Posted 11 March 2009 - 07:44 PM

You can indeed accomplish this with XML. You can read the XML data into a DataTable with the ReadXml Method of the DataTable class. Here's a simple way of accomplishing this

// <summary>
/// method for reading an XML file into a DataTable
/// </summary>
/// <param name="file">name (and path) of the XML file</param>
/// <returns></returns>
public DataTable ReadXML(string file)
{
	//create the DataTable that will hold the data
	DataTable table = new DataTable("XmlData");
	try
	{
		//open the file using a Stream
		using(Stream stream = new  FileStream(file, FileMode.Open, FileAccess.Read))
		{
			//create the table with the appropriate column names
			table.Columns.Add("Name", typeof(string));
			table.Columns.Add("Power", typeof(int));
			table.Columns.Add("Location", typeof(string));

			//use ReadXml to read the XML stream
			table.ReadXml(stream);

			//return the results
			return table;
		}				
	}
	catch (Exception ex)
	{
		return table;
	}
}



You can use that to help with data binding of any control that is a data binding control. Hope that helps :)
Was This Post Helpful? 1
  • +
  • -

#3 Tempus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-March 09

Re: Using XMl as a database/databinding

Posted 11 March 2009 - 11:02 PM

excellent, i had a feeling it was possible somehow :-)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1