So I'm starting to use XML and I'm trying to use it as a database of sorts. I've managed to save it off and read the whole thing in, but now the problem is that I want to be able to search through, get an item, and make it.

My current XML setup is below.

<?xml version="1.0" encoding="utf-8"?>
   <Name>Some Dude</Name>

So I'd like to be able to call for a "Object" of a certain index then use those details (both the index and the damage) to make an item.

I've tried a few different things but I wasn't able to get anything to work right. Any ideas?

7 Years
Discussion Span
Last Post by __avd

You can search for C# XPATH on Google for tons of information on this subject. I am not sure you will find exactly what you are looking for.

There may be a better alternative, or atleast worth your time to look at, and that is to use the existing power built into the DataSet class.

For example, you can create your own XML file based database by creating a DataSet with tables, and columns (the schema). You can load this dataset from a file, and make your changes, then save it back to the file.
Lets say you have a DataSet named Config that has several tables.
When your application starts, it can check to see if you have a file named MyConfig.xml, and if so then load it.


Now your application has all of the tables for this dataset loaded with data and ready to be used. Later when you want to save your changes back to the file:


Now because you have all of your data in the DataSet, you can use the standard (robust) features to search, filter, etc. this data.

foreach(DataRow data in Config.Tables["Items"].Select("Index=10"))
      MessageBox.Show( (string)data["Damage"] );

Hope this helps,


DataSet is has a solution of your problem.

Consider the following code:

DataSet ds = new DataSet();
            // Read XML File

            // Assign Reference of Object - DataTable
           //   DataTable dt=ds.Tables["Object"];
            dataGridView1.DataSource = ds.Tables["Object"];
            dataGridView2.DataSource = ds.Tables["SecondObject"];
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.