user726720
user726720

Reputation: 1247

List of type DataROW to XML

I have a list as below:

List<datarow> list =  getxml_table.AsEnumberable().ToList();

This contains XML DATA in each row. How do I copy this to XML file ? I tried using a XML serializer but it requires a parameterless constructor, so that's not possible.

Any other Ideas.

EDIT:

XML data inside the List<datarow> (this is just a sample for illustration purposes, actual data is quite huge). Each row contains the following XML.

<List>
<Listevent someelementdata ="false">
 <someelement>
  <moreelement morelementdata = "1234"/>
</someelement>
</Listevent>
</List>

Here is what I tried:

using (stringwriter stringwriter = new stringwriter (new stringbuilder()))
{
  xmlserializer xmlserializer = new xmlserializer(typeof(DataRow));
  xmlserializer.serialize(stringwriter, list);
  var string = stringwriter.string();
}

Upvotes: 0

Views: 360

Answers (1)

Andrey Korneyev
Andrey Korneyev

Reputation: 26886

First of all - DataRow itself does not contains data (at least if we're talking about standard ADO.NET DataRow). Data being stored in concrete "cell" of DataRow (something like DataRow["column_name"]).

Next - why do you need XmlSerializer at all? Maybe I still have not understood your problem completely - but for me it looks like you're having List<DataRow>, and in some cell of each row you're having some string containing xml data.

So you can just write these strings to file something like (pseudocode):

List<DataRow> list =  getxml_table.AsEnumberable().ToList();
using (var writer = new StreamWriter(@"c:\temp\1.txt"))
{
    foreach(var row in list)
    {
        writer.WriteLine(row["column_name"]);
    }
}

Upvotes: 1

Related Questions