Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > How to serialize nested arrays using XML attributes?

Reply
Thread Tools

How to serialize nested arrays using XML attributes?

 
 
Sinex
Guest
Posts: n/a
 
      05-02-2007
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>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Serialize XML without ?xml tag Neil Java 4 09-28-2009 04:22 PM
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
dealing with nested xml within nested xml within...... Ultrus Python 3 07-09-2007 09:00 PM
serialize to SQL Server Blob instead of XML serialize Gordz ASP .Net 3 06-07-2004 07:46 PM



Advertisments