473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Serialization of jagged Arrays Issue

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("chas sisdata")]
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.

Nov 24 '06 #1
4 4788
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("chas sisdata")]
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,
Gadget
Nov 24 '06 #2
I should add that the reason you can't remove the header node is because if
your class was something like:

class upsteps
{
WheelCollection wheels1;
WheelCollection wheels2;
}

then the deserializer would never know when the wheels1 collection had
finished and wheels2 started. Hence it needs the collection's node to tell
it to start the next object.
Ambiguity will not be tolerated :)

Cheers,
Gadget
Nov 25 '06 #3
thanx a lot for replying Gadget, but the problem is i dont know how to
make asp.net to generate wsdl of my choice. OR how can i hand code a
schema from a set of classes.

secondly, upsteps is not a class, its a jagged array of the "wheel"
class which is written below. I want to know that what should i do to
generate a proper xml of "upsteps" variable.

class returnType
{
wheel[][] upsteps;
}
class wheel
{
public string name;

public wheelmanufacturer[] _wheel manufacturer;
}

thanx for replying again. i need the solution urgently please if you
can answer or refer to some appropriate knowledge base........I will b
greatfull.

On Nov 25, 5:19 am, Gadget <gad...@sobell.netwrote:
I should add that the reason you can't remove the header node is because if
your class was something like:

class upsteps
{
WheelCollection wheels1;
WheelCollection wheels2;

}then the deserializer would never know when the wheels1 collection had
finished and wheels2 started. Hence it needs the collection's node to tell
it to start the next object.
Ambiguity will not be tolerated :)

Cheers,
Gadget
Nov 25 '06 #4
On 25 Nov 2006 08:36:23 -0800, Sahar wrote:
thanx a lot for replying Gadget, but the problem is i dont know how to
make asp.net to generate wsdl of my choice. OR how can i hand code a
schema from a set of classes.

secondly, upsteps is not a class, its a jagged array of the "wheel"
class which is written below. I want to know that what should i do to
generate a proper xml of "upsteps" variable.

class returnType
{
wheel[][] upsteps;
}
class wheel
{
public string name;

public wheelmanufacturer[] _wheel manufacturer;
}

thanx for replying again. i need the solution urgently please if you
can answer or refer to some appropriate knowledge base........I will b
greatfull.
Well there is no built-in method to handle multidimensional arrays, so you
either have to replace your existing solution with a collection of
collections, or write your own serializer/deserializer.
If the format of the XML is important then the second method is ideal. You
could simply have nested loops, starting an element tag in the outer,
looping through the variable-length inner, then closing the tag.
Look at XmlTextWriter; it's very easy to use.
You can then embed this in your class using the IXmlSerializable interface.
See
http://msdn2.microsoft.com/en-us/lib...ializable.aspx
for details.

Cheers,
Gadget
Nov 26 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: James dean | last post by:
I done a test and i really do not know the reason why a jagged array who has the same number of elements as a multidimensional array is faster here is my test. I assign a value and do a small...
3
by: James dean | last post by:
I have created algorithms in C# unsafe code and have fixed the arrays in memory for optimum performance. I use multidimensional arrays rather than jagged arrays. The algorithms i use usually read a...
1
by: Chris Wood | last post by:
I need to do a variable argument list in Managed C++, where each argument is a double array. I believe that this is impossible, because to do so I would need to make a jagged matrix of doubles,...
3
by: Ravi Singh (UCSD) | last post by:
Hello all I am trying to use jagged and multi-dimensional arrays in C++. In C# these work fine // for jagged arrays string jaggedArray = new string ; //for multidimensional arrays string...
1
by: xllx.relient.xllx | last post by:
Hi, I have two questions: 1.)Is it true that an rectangular array is really just an single dimensional array that lets itself be treated as a multi-dimensional array? For example the...
0
by: SaharImtiaz | last post by:
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...
5
by: TS | last post by:
is there some code somewhere that does this? i have a jagged array that is not jagged, it has an equal number of rows and columns in each array so it should convert but want to get the code to do...
0
by: ksallem | last post by:
I have the following class that declares a jagged array named procedimentosRealizadosField()(). When I try to deserialize an XML file into an object of this class all fields are loaded correctly,...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.