[quoted text, click to view] On 23 Nov 2006 22:57:09 -0800, Sahar wrote:
> Hi there,
>
> I m trying to return an object (of my own written class) from a web
> service that contains jagged Arrays as public variables. Asp.Net is
> showing me the its serialized version on the browser when i invoke the
> service during test.
>
> Code:
> public class returnType
> {
> [System.Xml.Serialization.XmlElementAttribute("chassisdata")]
> public _chassisdata[] chassisdata;
>
> [XmlArray(),XmlArrayItem("wheel", typeof(_wheel[]),IsNullable=false)]
> public _wheel[][] upsteps;
>
>
> [XmlArray(),XmlArrayItem("wheelsize",
> typeof(_wheelsize[]),IsNullable=false)]
> public _wheelsize[][] alloywheel;
>
> [System.Xml.Serialization.XmlAttributeAttribute()]
> public string id;
>
> }
> Result:
> <upsteps>
> <wheels>
> <_wheel>
> ....
> ....
> </_wheel>
> <_wheel>
> ....
> ....
> </_wheel>
> </wheel>
> </upsteps>
> <alloywheels>
> <wheelsize>
> <wheelsize size="">
> ....
> ....
> </wheelsize>
> <wheelsize size="">
> ....
> ....
> </wheelsize>
> </wheelsize>
> </alloywheels>
> --------------------------------------------------------
> The Problem is,I want to change the serialized xml as follows
>
> <upsteps>
> <_wheel>
> ....
> ....
> </_wheel>
> <_wheel>
> ....
> ....
> </_wheel>
> </upsteps>
> <alloywheels>
> <wheelsize size="">
> ....
> ....
> </wheelsize>
> <wheelsize size="">
> ....
> ....
> </wheelsize>
> </alloywheels>
>
> Can any body help me?
>
> thanx in Advance.
You can't remove the parent node in this way using the built-in
serialization.
The built in system is not intended to provide ways of generating XML for
use in other people's schemas. The fact it sometime can is a bonus, but
it's actually there to serialize and deserialize object in the most
efficient manner it can.
The serializer internally uses reflection to read the object type you
provided and builds a set of .NET code in C# involving XmlTextReaders and
writers. That's it, no more, no less. You can even view the source code if
you get the command line arguments right (Google for more info on doing
this).
If you really want a set of classes to match an external schema then
hand-code it yourself, or look at XSD.exe (although I often prefer the
hand-coding :)).
Cheers,