serializing List<List<string>>

  • Thread starter Thread starter parez
  • Start date Start date
P

parez

Hi,

I am trying to serialize List<List<string>> .

With the following code

[XmlArrayItem("DataRow")]
[XmlArray("DataRows")]
public List<List<string>> DataRows { get; set; }


I get the following

<DataRows>
<DataRow>
<string>123</string>
<string>432</string>
<string>423</string>
</DataRow>
<DataRow>
<string>4543</string>
<string>53</string>
<string>533</string>
</DataRow>
</DataRows>


I want the output to have <DataRowItem> instead of <string>.

One way it mite work is
if I "box" List<string> as SomeList and then have List<SomeList>..But
there should be an easier way.

TIA
 
Hi,

I am trying to serialize List<List<string>> .

With the following code

[XmlArrayItem("DataRow")]
[XmlArray("DataRows")]
public List<List<string>> DataRows { get; set; }

I get the following

<DataRows>
<DataRow>
<string>123</string>
<string>432</string>
<string>423</string>
</DataRow>
<DataRow>
<string>4543</string>
<string>53</string>
<string>533</string>
</DataRow>
</DataRows>

I want the output to have <DataRowItem> instead of <string>.

One way it mite work is
if I "box" List<string> as SomeList and then have List<SomeList>..But
there should be an easier way.

TIA

That didnt work...


I tried
[XmlArrayItem("DataRow",typeof(Datarow))]
[XmlArray("DataRows")]
public List<Datarow> DataRows { get; set; }




public class Datarow
{
public Datarow()
{
DataRow = new List<string>();
}
[XmlArrayItem("DataRowItems")]

public List<string> DataRow { get; set; }
}

and this is what i got..

<DataRows>
<DataRow>
<DataRow>
<DataRowItems>123</DataRowItems>
<DataRowItems>432</DataRowItems>
<DataRowItems>423</DataRowItems>
</DataRow>
</DataRow>
<DataRow>
<DataRow>
<DataRowItems>4543</DataRowItems>
<DataRowItems>53</DataRowItems>
<DataRowItems>533</DataRowItems>
</DataRow>
</DataRow>
</DataRows>



any one..
 
I am trying to serialize List<List<string>> .
With the following code
[XmlArrayItem("DataRow")]
[XmlArray("DataRows")]
public List<List<string>> DataRows { get; set; }
I get the following

I want the output to have <DataRowItem> instead of <string>.
One way it mite work is
if I "box" List<string> as SomeList and then have List<SomeList>..But
there should be an easier way.

That didnt work...

I tried
[XmlArrayItem("DataRow",typeof(Datarow))]
[XmlArray("DataRows")]
public List<Datarow> DataRows { get; set; }

public class Datarow
{
public Datarow()
{
DataRow = new List<string>();
}
[XmlArrayItem("DataRowItems")]

public List<string> DataRow { get; set; }
}

and this is what i got..

<DataRows>
<DataRow>
<DataRow>
<DataRowItems>123</DataRowItems>
<DataRowItems>432</DataRowItems>
<DataRowItems>423</DataRowItems>
</DataRow>
</DataRow>
<DataRow>
<DataRow>
<DataRowItems>4543</DataRowItems>
<DataRowItems>53</DataRowItems>
<DataRowItems>533</DataRowItems>
</DataRow>
</DataRow>
</DataRows>

any one..

Any body.. somebody..
 
[...]
Any body.. somebody..

For what it's worth, 3 hours since the last post isn't really enough time
for there to be any sense in being impatient.

As for the actual question, I'm no expert in serialization, but it may be
that you simply can't do what you want using only the XmlSerialization
attributes. If not, it is actually not that hard to implement
ISerializable so that you have more control over the output.

One possible option would be to make your collection a
List<List<DataRowItem>>, using the default behavior for that property, but
implementing ISerializable on the (newly defined) DataRowItem class such
that it will serialize as "<DataRowItem>xxxx</DataRowItem>".

Pete

Thanks..

i gave up on it..

i am going to go with

<DataRows>
<DataRow>
<string>123</string>
<string>432</string>
<string>423</string>
</DataRow>
<DataRow>
<string>4543</string>
<string>53</string>
<string>533</string>
</DataRow>
</DataRows>

I am going to ask the server guys to change the xml... they owe me
one.. actually a lot...
 

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

Back
Top