How to serialize nested arrays using XML attributes?

Discussion in 'ASP .Net Web Services' started by Sinex, May 2, 2007.

  1. Sinex

    Sinex Guest

    Hi ,

    I have some problem in XML Serialization. Basically.the trouble is when I am
    trying to serialize nested ArrayList (or arrays). The serializer is not able
    to determine the type of elementes stored in the nested (inner) ArrayList.
    Heres some sample code with the SOAP envelope that is generated and I have
    mentioned the SOAP envelope that is required at the end. See if you can make
    out nething that I am missing..



    class part

    {

    public int f1;

    public int f2;

    }

    class machine

    {

    [XmlArray(ElementName="parts")]

    [XmlArrayItem(ElementName="part", Type=typeof(part))]

    public ArrayList manyParts;

    }



    class webservice

    {

    [return: XmlElement(typeof(machines[]))]

    public ArrayList mywebmethod()

    {

    part p1 = new part(); p1.f1 = 10; p1.f2 = 20;

    part p2 = new part(); p2.f1 = 30; p2.f2 = 40;

    part p3 = new part(); p1.f1 = 10; p1.f2 = 20;

    part p4 = new part(); p2.f1 = 30; p2.f2 = 40;

    machine m1 = new machine();

    m1.manyParts = new ArrayList(2);

    m1.Add(p1); m1.Add(p2);

    machine m2 = new machine();

    m2.manyParts = new ArrayList(2);

    m2.Add(p3); m1.Add(p4);

    ArrayList manyMachines = new ArrayList(2);

    manyMachines.Add(m1); manyMachines.Add(m2);


    return manyMachines;

    }
    }



    Serialized SOAP being generated:

    <machines>

    <machine>

    <parts>

    <part xsi:nil="true" />

    <part xsi:nil="true" />

    <parts>

    </machine>

    </machines>



    Required SOAP format:

    <machines>

    <machine>

    <parts>

    <part>

    <f1>10</f1>

    <f2>20</f2>

    </part>

    <part>

    <f1>30</f1>

    <f2>40</f2>

    </part>

    <parts>

    </machine>

    </machines>
     
    Sinex, May 2, 2007
    #1
    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. Gordz
    Replies:
    3
    Views:
    3,985
    John Oakes
    Jun 7, 2004
  2. Ultrus
    Replies:
    3
    Views:
    411
    Stefan Behnel
    Jul 9, 2007
  3. Philipp
    Replies:
    21
    Views:
    1,183
    Philipp
    Jan 20, 2009
  4. Neil
    Replies:
    4
    Views:
    1,621
    Mike Schilling
    Sep 28, 2009
  5. john harkin
    Replies:
    1
    Views:
    863
    john harkin
    Sep 23, 2004
Loading...

Share This Page