0

I want to use an xml-file for storing my program data. The structure of the xml looks like this:

<?xml version="1.0" standalone="yes"?>
<Data>
    <Projects>
        <Project>
            <Name>Name1</Name>
            <Description>Description1</Description>
        </Project>
        <Project>
            <Name>Name2</Name>
            <Description>Description2</Description>
        </Project>
    </Projects>
</Data>

I want to use a DataSet since it offers the easy reading and writing of xml structures. But the question is, how to read and write the values of the <Project>-Nodes? I can access the <Projects>-Node, but then i don't know how to continue, since the single Projects aren't tables i guess. So, how can i access the nodes in the depth three (Data->Projects->Project)? I think this must work somehow, since reading the file and outputting it on the console does work.

AquilaRapax
  • 1,086
  • 8
  • 22

3 Answers3

0

You better try that with a class Data that has a list of objects Project it is easier to serialize/deserialize . I dont think its easier to read/write xml with a dataset .

isioutis
  • 304
  • 2
  • 13
0

Rather then a DataSet I suggest you look at using XDocument and XElement instead, since they can offer much better API for accessing items in the XML structure.

http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx

Another link which may help you get started:

How to Get XML Node from XDocument

Community
  • 1
  • 1
Jason Evans
  • 28,906
  • 14
  • 90
  • 154
  • Hm... sounds good. I thought it would be easier to use `DataSet`s but it seems not to be the right way. I'll have a look for the classes you (and Daniel) suggested. Thanks... – AquilaRapax May 23 '12 at 12:07
0

It sounds like DataSet isn't the right way for you to go. It is not intended to be a general purpose mechanism for reading and writing arbitrary XML.

If you're using .NET Framework 4 or later, I suggest using XDocument instead of DataSet.

If you're using an older .NET Framework version then there are plenty of other options, including XmlDocument, XmlReader, and XmlSerlializer. Which to choose depends on where your data is coming from and how you want to process it.

Daniel Renshaw
  • 33,729
  • 8
  • 75
  • 94