Csv Serialisation via Xml

B

bg_ie

Hi,

I have a comma seperated file which I use to store data, and a
simplified version of it looks like this -

TestPeriod1 , ,
,TestTime , 55
,TestAction ,
, Phase1
, Phase2
,RunTest ,
, Test1
, Test2
, Test2
,
Test1
TestPeriod2 , ,
,TestTime , 10
,TestAction , Phase2
,RunTest , Test1

TestPeriod3 , ,
,TestAction , Phase1
,RunTest , Test2


Since I have no TestTime for TestPeriod3, I use a default time. Note
also that TestPeriod1's TestAction has two values - Phase1 and Phase2,
and its RunTest has 4 values, with Test1 and Test2 appearing twice.

What I'd like to do is represent this data structure in c# using a
class called TestInformation. This class would then contain an array
of type TestPeriod used to store TestPeriod1, TestPeriod2 etc. The
TestPeriod class would then contain a TestTime Member, an array of
type TestAction and an array of type RunTest.

Now as I said, the above is a simplification of what I'm actually
using and this structure is subject to change over time. Therefore,
I'm thinking that my first stage might be to convert the above comma
seperated file to xml first. Would you recommend this step? If so, how
would you represent in xml the fact that TestPeriod1's TestAction has
two values Phase1 and Phase2, and that the Test1 and Test2 values are
represented twice?

Secondly, once in xml format, how difficult would it be to serialize
an object of type TestInformation from my xml file?

Any other suggestions or tips?

Thanks,

Barry.
 
A

auratius

on the second question on how to serialize an object to XML by using
Visual C#

Here is the code

using System;

public class clsPerson
{
public string FirstName;
public string MI;
public string LastName;
}

class class1
{
static void Main(string[] args)
{
clsPerson p=new clsPerson();
p.FirstName = "Jeff";
p.MI = "A";
p.LastName = "Price";
System.Xml.Serialization.XmlSerializer x = new
System.Xml.Serialization.XmlSerializer(p.GetType());
x.Serialize(Console.Out, p);
Console.WriteLine();
Console.ReadLine();
}
}


Regards

http://www.auratius.co.za

Auratius
 
C

Champika Nirosh

what is this really.. is this a index page of a book.. or is this some thing
else..
If this -> ",TestTime , 55" is correct then you have treat this as a node
int the XML and

here in this -> ,TestAction , case you have to treat Phase 1 and 2 as two
node in the XML with a attribute.
, Phase1
, Phase2

You have to take the /r/n to identify new nodes but in case one you have to
hevily depend on the attribute you add to indentyfy the node and seperate it
as you create the class..


Answering to the question of whether the approach to create a XML in the
middle.. it heavily depend on your requirement, you don't have to create a
XML if you do not want your data to be converted to a nutral format before
the processing.. I would rather avoid the comma seperated file and evaluate
the possibility of creating the XML at the first place itself, and failing
that, I would prefer not to create a XML in the middle.. but it all depend
on what you are trying to achieve here..

Nirosh.
 
S

Samuel R. Neff

I think you'll find it easier to read the data into a custom object
sturcture directly instead of working with XML. Then if you need XML
you can serialize that custom object out as XML but that would be
totally unrelated to the CSV format.

HTH,

Sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top