474,045 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Seri alization.XmlEl ementAttribute( "chassisdat a")]
public _chassisdata[] chassisdata;

[XmlArray(),XmlA rrayItem("wheel ", typeof(_wheel[]),IsNullable=fa lse)]
public _wheel[][] upsteps;
[XmlArray(),XmlA rrayItem("wheel size",
typeof(_wheelsi ze[]),IsNullable=fa lse)]
public _wheelsize[][] alloywheel;

[System.Xml.Seri alization.XmlAt tributeAttribut e()]
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 4833
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.Seri alization.XmlEl ementAttribute( "chassisdat a")]
public _chassisdata[] chassisdata;

[XmlArray(),XmlA rrayItem("wheel ", typeof(_wheel[]),IsNullable=fa lse)]
public _wheel[][] upsteps;
[XmlArray(),XmlA rrayItem("wheel size",
typeof(_wheelsi ze[]),IsNullable=fa lse)]
public _wheelsize[][] alloywheel;

[System.Xml.Seri alization.XmlAt tributeAttribut e()]
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 wheelmanufactur er[] _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 wheelmanufactur er[] _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 multidimensiona l 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 IXmlSerializabl e 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
2755
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 calculation. Even if i initialise the jagged array inside the function it is still much faster. Are these results correct?. If i put the initialisation loop in the constructor its ridiculously faster but even here its 4 times faster...is this correct?...
3
2582
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 bitmap file sequentially so no random accessing different parts of the array. I know in microsoft site it says to use jagged arrays but in this case with reading a sequential file the performance difference will not be as good as a...
1
1284
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, which is not supported. Does anyone know if this is impossible, or if there is some other way to do this? Using System.Array rather than double __gc is not an option for me. Thanks -- Chris
3
2212
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 multidimensionalArray = new string
1
10353
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 following declaration: int rectangular = new int;
0
1223
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 browser when i invoke the service during test. Code: public class returnType { public _chassisdata chassisdata;
5
10393
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 it somewhere. thanks
0
1991
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, except for the procedimentosRealizadosField()() which returns nothing. Previously, I changed the declaration of the method from : <System.Xml.Serialization.XmlArrayItemAttribute("procedimentosRevisao",...
17
7279
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 to show the array data to the end user. Can I do that? How?
0
10337
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
12140
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11602
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
12023
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
8698
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6652
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6837
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3971
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.