custom serialization

Discussion in 'ASP .Net' started by =?Utf-8?B?QVZM?=, May 4, 2007.

  1. Hi,
    I'm new serialization concepts....I need some hwlp..
    I've a class defined as follows

    class CustomSerialization1
    {
    private string s;

    public string Test
    {
    get { return s; }
    set { s = value; }
    }

    private int i;

    public int Test1
    {
    get { return i; }
    set { i = value; }
    }
    CustomSerialization1 obj = new CustomSerialization1();
    obj.Test = "vijaya,wajid,vani";
    object.Test1 = 3;
    }

    if want the the output to be sth below after applying serializatiion

    <Task>
    <Test>
    <TestInnner>Vijaya</TestInnner>
    <TestInnner>wajid</TestInnner>
    <TestInnner>vani</TestInnner>
    </Test>
    <Test1>3</Test3>
    </Task>

    Basically I want to control teh way inwhich my Test property will be
    displayed during serialization and deserialization....


    please help me out..just let me know if this is possible by any means...
    either thru XmlSerialization or Custom Serialziation...
     
    =?Utf-8?B?QVZM?=, May 4, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?QVZM?=

    bruce barker Guest

    pretty trivial. you implement IXmlSerializable:

    public void WriteXml(XmlWriter writer)
    {
    writer.WriteStartElement("Taskt");
    writer.WriteStartElement("Test");
    string[] values = s.Split(',');
    for (int i=0; i < values.Length; ++i)
    {
    writer.WriteStartElement("Test1");
    writer.WriteString(values);
    writer.WriteEndElement();
    }
    writer.WriteEndElement();

    writer.WriteStartElement("Test1");
    writer.WriteString(Test1.ToString());
    writer.WriteEndElement();
    writer.WriteEndElement();
    }
    public void ReadXml(XmlReader reader)
    {
    // left to reader
    }



    AVL wrote:
    > Hi,
    > I'm new serialization concepts....I need some hwlp..
    > I've a class defined as follows
    >
    > class CustomSerialization1
    > {
    > private string s;
    >
    > public string Test
    > {
    > get { return s; }
    > set { s = value; }
    > }
    >
    > private int i;
    >
    > public int Test1
    > {
    > get { return i; }
    > set { i = value; }
    > }
    > CustomSerialization1 obj = new CustomSerialization1();
    > obj.Test = "vijaya,wajid,vani";
    > object.Test1 = 3;
    > }
    >
    > if want the the output to be sth below after applying serializatiion
    >
    > <Task>
    > <Test>
    > <TestInnner>Vijaya</TestInnner>
    > <TestInnner>wajid</TestInnner>
    > <TestInnner>vani</TestInnner>
    > </Test>
    > <Test1>3</Test3>
    > </Task>
    >
    > Basically I want to control teh way inwhich my Test property will be
    > displayed during serialization and deserialization....
    >
    >
    > please help me out..just let me know if this is possible by any means...
    > either thru XmlSerialization or Custom Serialziation...
     
    bruce barker, May 4, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    8
    Views:
    2,271
    deadsea
    Jan 2, 2005
  2. Replies:
    3
    Views:
    1,055
  3. Dimitri Ognibene
    Replies:
    4
    Views:
    796
    Dimitri Ognibene
    Sep 2, 2006
  4. Maury

    Custom serialization in object

    Maury, Oct 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    290
    Maury
    Oct 20, 2006
  5. Ramunas Urbonas
    Replies:
    1
    Views:
    411
    Dino Chiesa [Microsoft]
    Jul 27, 2004
Loading...

Share This Page