serializing List<List<string>>

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • parez

    serializing List<List<string>>

    Hi,

    I am trying to serialize List<List<strin g>.

    With the following code

    [XmlArrayItem("D ataRow")]
    [XmlArray("DataR ows")]
    public List<List<strin g>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 <DataRowItemins tead 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
  • parez

    #2
    Re: serializing List&lt;List&lt ;string&gt;&gt;

    On Apr 22, 11:22 am, parez <psaw...@gmail. comwrote:
    Hi,
    >
    I am trying to serialize List<List<strin g>.
    >
    With the following code
    >
    [XmlArrayItem("D ataRow")]
    [XmlArray("DataR ows")]
    public List<List<strin g>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 <DataRowItemins tead 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("D ataRow",typeof( Datarow))]
    [XmlArray("DataR ows")]
    public List<DatarowDat aRows { get; set; }




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

    public List<stringData Row { get; set; }
    }

    and this is what i got..

    <DataRows>
    <DataRow>
    <DataRow>
    <DataRowItems>1 23</DataRowItems>
    <DataRowItems>4 32</DataRowItems>
    <DataRowItems>4 23</DataRowItems>
    </DataRow>
    </DataRow>
    <DataRow>
    <DataRow>
    <DataRowItems>4 543</DataRowItems>
    <DataRowItems>5 3</DataRowItems>
    <DataRowItems>5 33</DataRowItems>
    </DataRow>
    </DataRow>
    </DataRows>



    any one..

    Comment

    • parez

      #3
      Re: serializing List&lt;List&lt ;string&gt;&gt;

      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<strin g>.
      >
      With the following code
      >
      [XmlArrayItem("D ataRow")]
      [XmlArray("DataR ows")]
      public List<List<strin g>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 <DataRowItemins tead 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("D ataRow",typeof( Datarow))]
      [XmlArray("DataR ows")]
      public List<DatarowDat aRows { get; set; }
      >
      public class Datarow
      {
      public Datarow()
      {
      DataRow = new List<string>();
      }
      [XmlArrayItem("D ataRowItems")]
      >
      public List<stringData Row { get; set; }
      }
      >
      and this is what i got..
      >
      <DataRows>
      <DataRow>
      <DataRow>
      <DataRowItems>1 23</DataRowItems>
      <DataRowItems>4 32</DataRowItems>
      <DataRowItems>4 23</DataRowItems>
      </DataRow>
      </DataRow>
      <DataRow>
      <DataRow>
      <DataRowItems>4 543</DataRowItems>
      <DataRowItems>5 3</DataRowItems>
      <DataRowItems>5 33</DataRowItems>
      </DataRow>
      </DataRow>
      </DataRows>
      >
      any one..
      Any body.. somebody..

      Comment

      • Peter Duniho

        #4
        Re: serializing List&lt;List&lt ;string&gt;&gt;

        On Tue, 22 Apr 2008 15:15:20 -0700, parez <psawant@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 XmlSerializatio n
        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<DataR owItem>>, using the default behavior for that property, but
        implementing ISerializable on the (newly defined) DataRowItem class such
        that it will serialize as "<DataRowItem>x xxx</DataRowItem>".

        Pete

        Comment

        • parez

          #5
          Re: serializing List&lt;List&lt ;string&gt;&gt;

          On Apr 22, 6:47 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.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 XmlSerializatio n
          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<DataR owItem>>, using the default behavior for that property, but
          implementing ISerializable on the (newly defined) DataRowItem class such
          that it will serialize as "<DataRowItem>x xxx</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...



          Comment

          Working...