XML serialization and dataset.XMLReader with same XML file possible?

I have a timer application that I am working on that uses two separate XML files to store data. XML File 1 stores summary data for the time allotted and the name of the game. XML File 2 stores the contents of a dataset which is more of a narrative of events. This allows the user to load saved data and basically start from where they left off. I am using serialize/deserialize for XML File 1 and loading the values into variables and dataset.XMLReader(xml file path) to load the dataset.

I would like to combine the two XML files, but after a couple of hours of searching around and trying bits of different code I have hit an impasse. Is what I am attempting to do even possible?

One of my thoughts was instead of using serialization/deserialization for XML File 1, retool my application (ugh) to load these variables into a dataset as well, then populate the variables from there. But then I still have the problem with dataset.XMLReader(xml file path) running into issues with either multiple root nodes or inconsistent node structures.

Questions, comments or holy grail solution that makes my life easier in 3 lines of code much appreciated.

Code for XML File 1:

    static public void SerializeToXML(TimeData times, String filename)
    {
        XmlSerializer serializer = new XmlSerializer(typeof(TimeData));
        TextWriter textWriter = new StreamWriter(filename);
        serializer.Serialize(textWriter, times);
        textWriter.Close();
    }

    private void DeSerializeFromXML(string filename)
    {
        XmlSerializer serializer = new
        XmlSerializer(typeof(TimeData));

        FileStream fs = new FileStream(filename, FileMode.Open);
        XmlReader reader = XmlReader.Create(fs);

        TimeData i;
        i = (TimeData)serializer.Deserialize(reader);            

        [bunch of code to convert ticks to readable time values and whatnot]

        fs.Close();
    }


XML File 1:

<?xml version="1.0" encoding="utf-8"?>
<TimeData>
  <Name>Test</Name>
  <TimeAllotted>76000000</TimeAllotted>
  <CumulativeTime>0</CumulativeTime>
  <TimeRemaining>76000000</TimeRemaining>
</TimeData>

Code for XML File 2:

Essentially it is just ds.ReadXml(xmlFileName); and ds.WriteXml(newFilename);

XML File 2:
<?xml version="1.0" encoding="utf-8"?>
<Detail>
  <Timer>
    <ID>1</ID>
    <Segment>1</Segment>
    <Event>Start</Event>
    <Value>00:00:00</Value>
    <Notes>Some Text</Notes>
  </Timer>
    <Timer>
      <ID>2</ID>
      <Segment>1</Segment>
      <Event>Start</Event>
      <Value>00:00:00</Value>
      <Notes>Some More Text</Notes>
  </Timer>
</Detail>

What I would like the resulting XML file to look like, or at least something similar containing all the data from above:

XML File 1:
<?xml version="1.0" encoding="utf-8"?>
<TimeApp>
  <TimeData>
    <Name>Test</Name>
    <TimeAllotted>76000000</TimeAllotted>
    <CumulativeTime>0</CumulativeTime>
    <TimeRemaining>76000000</TimeRemaining>
  </TimeData>
  <Detail>
    <Timer>
      <ID>1</ID>
      <Segment>1</Segment>
      <Event>Start</Event>
      <Value>00:00:00</Value>
      <Notes>Some Text</Notes>
    </Timer>
      <Timer>
        <ID>2</ID>
        <Segment>1</Segment>
        <Event>Stop</Event>
        <Value>00:00:00</Value>
        <Notes>Some More Text</Notes>
    </Timer>
  </Detail>
</TimeApp>

Answers


The problem is solved and I did it by utilizing the age old "one step back, two steps forward" method.

Instead of housing the data I want to save in the XML file in a data table and a group of class variables, I am putting both in separate data tables within the same dataset. At this point all that needs to be done is a dataset.GetXML, which is then saved out to an extremal file. To reload, simply use dataset.ReadXML(xmlFilename).

Problem solved. Hope that this helps someone in a similar pickle.


Need Your Help

Android, Swarm: how to download multiple leaderboards on the same thread?

java android

I am writing android game that uses Swarm database. My problem is that they only allow to store one variable and I need three. So I created nine leaderborad to represent different variable sets.

Remove Hyperlinks Preserve Cell Format

excel vba excel-vba hyperlink

I have some cells in a worksheet that contain Inserted hyperlinks. I want to remove the hyperlinks and leave the "friendly name" in the cell. I can do this with: