473,473 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

serializing List<List<string>>

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 <DataRowIteminstead of <string>.

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

TIA
Jun 27 '08 #1
4 3927
On Apr 22, 11:22 am, parez <psaw...@gmail.comwrote:
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 <DataRowIteminstead of <string>.

One way it mite work is
if I "box" List<stringas 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<DatarowDataRows { get; set; }


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

public List<stringDataRow { 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..
Jun 27 '08 #2
On Apr 22, 1:12 pm, parez <psaw...@gmail.comwrote:
On Apr 22, 11:22 am, parez <psaw...@gmail.comwrote:
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 <DataRowIteminstead of <string>.
One way it mite work is
if I "box" List<stringas 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<DatarowDataRows { get; set; }

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

public List<stringDataRow { 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..
Jun 27 '08 #3
On Tue, 22 Apr 2008 15:15:20 -0700, parez <ps*****@gmail.comwrote:
[...]
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
Jun 27 '08 #4
On Apr 22, 6:47 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Tue, 22 Apr 2008 15:15:20 -0700, parez <psaw...@gmail.comwrote:
[...]
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...

Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: gbgbgbgb | last post by:
Hi, I have a definition bool operator<(string s_s, string s_t) { .... } and a variable list<string> concomp;
2
by: s | last post by:
I'm getting compile errors on the following code: <code> #include <iostream> #include <fstream> #include <list> #include <string> using namespace std;
3
by: aquanutz | last post by:
Ok, I have a list of strings (list<string> stringList) that I want to sort alphabetcially, only "sort(stringList.begin(), stringList.end()); ) does not work. Any insight would be helpful. Thanks!
3
by: Abhi | last post by:
In the following hypothetical example I want to build a generic list of unique string items. How should I implement the pred function so that it returns true/false if target string exists in the...
6
by: buzzweetman | last post by:
Many times I have a Dictionary<string, SomeTypeand need to get the list of keys out of it as a List<string>, to pass to a another method that expects a List<string>. I often do the following: ...
4
by: Mark Rae | last post by:
Hi, Is it possible to create a case-insensitive List<stringcollection? E.g. List<stringMyList = new List<string>; MyList.Add("MyString"); So that:
4
by: rsa_net_newbie | last post by:
Hi there, I have a Managed C++ object (in a DLL) which has a method that is defined like ... Generic::List<String^>^ buildList(String^ inParm) Now, when I compile it, I get "warning C4172:...
2
by: Assimalyst | last post by:
Hi I have a Dictionary<string, List<string>>, which i have successfully filled. My problem is I need to create a filter expression using all possible permutations of its contents. i.e. the...
3
by: banangroda | last post by:
Compilation fails at "line.insert(line.end(), x.begin(), i);" and I can't figure out why. Here is the code: /* 5-1. Design and implement a program to produce a permuted index. A permuted index...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.