473,219 Members | 1,576 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,219 software developers and data experts.

Cleanest way to change order of serialized el's?

Hi,

I would like to know the cleanest way to change the serialization of my
Line class from:

<Line staStart="2327.02" length="10.00000003390744">
<End>549016.570965 57945.741122</End>
<Start>549019.590988 57955.274194</Start>
</Line>

to

<Line staStart="2327.02" length="10.00000003390744">
<Start>549019.590988 57955.274194</Start>
<End>549016.570965 57945.741122</End>
</Line>

i.e. the only change is the order of the Start and End elements. This is
really a minor issue but if it does not involve too much work, I'd like to
have it this way. My Line class has this interface:

public __gc class Line {

public:
Line();

[System::Xml::Serialization::XmlAttributeAttribute]
__property double get_length();
__property void set_length(double l);

[System::Xml::Serialization::XmlIgnoreAttribute]
bool dirSpecified;
[System::Xml::Serialization::XmlAttributeAttribute]
__property double get_dir();
__property void set_dir(double d);

[System::Xml::Serialization::XmlIgnoreAttribute]
bool staStartSpecified;
[System::Xml::Serialization::XmlAttributeAttribute]
__property double get_staStart();
__property void set_staStart(double s);

[System::Xml::Serialization::XmlElement]
__property Point3D* get_Start();
__property void set_Start(Point3D* p);

[System::Xml::Serialization::XmlElement]
__property Point3D* get_End();
__property void set_End(Point3D* p);

private:

Point3D *m_start, *m_end;
double m_staStart, m_dir;
};

As you see I'm using MC++. That shouldn't matter though, if you have a
solution in C# I'd gladly accept it. I'm thinking I should put m_start and
m_end in an ArrayList, but to get the desired result it would mean m_start
and m_end would have to be different datatypes (new classes Start and End):

[XmlElementAttribute(Type=__typeof(Start),ElementNa me="Start")]
[XmlElementAttribute(Type=__typeof(End),ElementName ="End")]
__property ArrayList* get_Collection();
__property void set_Collection(ArrayList* arr);

Any other ideas?
Thanks in advance!

--
Daniel
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 12 '05 #1
2 2279
Hi Daniel

Why don't you try creating a schema file with the xml structure that you
want, then use the xsd tool to generate the class for you? You won't be able
to do this with C++ (No CodeDOM support), but you would get a C# class out of
it...

I tried this (note the simplification of your Start and End elements to
strings - you would probably want to do this as a list of a simple type with
the precision that you require, then limit the list length). And I just used
decimal for the attributes...

So here's the xsd:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Line">
<xs:complexType>
<xs:sequence>
<xs:element name="Start" type="xs:string"/>
<xs:element name="End" type="xs:string"/>
</xs:sequence>
<xs:attribute name="staStart" type="xs:decimal" use="required"/>
<xs:attribute name="length" type="xs:decimal" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>

With this, the cs class generated contains just public fields - I've
modified the Start and End to use properties, and have this class:

//------------------------------------------------------------------------------
// <autogenerated>
// This code was generated by a tool.
// Runtime Version: 1.1.4322.2032
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </autogenerated
//------------------------------------------------------------------------------

//
// This source code was auto-generated by xsd, Version=1.1.4322.2032.
//
using System.Xml.Serialization;
/// <remarks/>
[System.Xml.Serialization.XmlRootAttribute(Namespac e="", IsNullable=false)]
public class Line {

/// <remarks/>
private string mStart
[System.Xml.Serialization.XmlElementAttribute(Form= System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string Start
{
get
{
return mStart;
}
set
{
mStart = value;
}
}

/// <remarks/>
private string mEnd
[System.Xml.Serialization.XmlElementAttribute(Form= System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string End
{
get
{
return mEnd;
}
set
{
mEnd = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public System.Decimal staStart;

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public System.Decimal length;
}

When you serialize a Line this with this code:

using System;

namespace TestLine
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//

Line l = new Line();
l.Start = "549019.590988 57955.274194";
l.End = "549016.570965 57945.741122";
l.length = 10.00000003390744M;
l.staStart = 2327.02M;

System.Xml.Serialization.XmlSerializer s = new
System.Xml.Serialization.XmlSerializer(typeof(Line ), "");
s.Serialize(Console.Out, l, null);

}
}
}
then you get this output:

<?xml version="1.0" encoding="UTF-8"?>
<Line xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/
2001/XMLSchema-instance" staStart="2327.02" length="10.00000003390744">
<Start>549019.590988 57955.274194</Start>
<End>549016.570965 57945.741122</End>
</Line>

I'm not sure that this helps you much - in the C# code, when you switch the
order of the Start and End properties, then the serialization also switches...

Nigel Armstrong

"Daniel Lidström" wrote:
Hi,

I would like to know the cleanest way to change the serialization of my
Line class from:

<Line staStart="2327.02" length="10.00000003390744">
<End>549016.570965 57945.741122</End>
<Start>549019.590988 57955.274194</Start>
</Line>

to

<Line staStart="2327.02" length="10.00000003390744">
<Start>549019.590988 57955.274194</Start>
<End>549016.570965 57945.741122</End>
</Line>

i.e. the only change is the order of the Start and End elements. This is
really a minor issue but if it does not involve too much work, I'd like to
have it this way. My Line class has this interface:

public __gc class Line {

public:
Line();

[System::Xml::Serialization::XmlAttributeAttribute]
__property double get_length();
__property void set_length(double l);

[System::Xml::Serialization::XmlIgnoreAttribute]
bool dirSpecified;
[System::Xml::Serialization::XmlAttributeAttribute]
__property double get_dir();
__property void set_dir(double d);

[System::Xml::Serialization::XmlIgnoreAttribute]
bool staStartSpecified;
[System::Xml::Serialization::XmlAttributeAttribute]
__property double get_staStart();
__property void set_staStart(double s);

[System::Xml::Serialization::XmlElement]
__property Point3D* get_Start();
__property void set_Start(Point3D* p);

[System::Xml::Serialization::XmlElement]
__property Point3D* get_End();
__property void set_End(Point3D* p);

private:

Point3D *m_start, *m_end;
double m_staStart, m_dir;
};

As you see I'm using MC++. That shouldn't matter though, if you have a
solution in C# I'd gladly accept it. I'm thinking I should put m_start and
m_end in an ArrayList, but to get the desired result it would mean m_start
and m_end would have to be different datatypes (new classes Start and End):

[XmlElementAttribute(Type=__typeof(Start),ElementNa me="Start")]
[XmlElementAttribute(Type=__typeof(End),ElementName ="End")]
__property ArrayList* get_Collection();
__property void set_Collection(ArrayList* arr);

Any other ideas?
Thanks in advance!

--
Daniel
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Nov 12 '05 #2
Hi Higel,
On Wed, 24 Nov 2004 11:53:03 -0800, Nigel Armstrong wrote:
Hi Daniel

Why don't you try creating a schema file with the xml structure that you
want, then use the xsd tool to generate the class for you? You won't be able
to do this with C++ (No CodeDOM support), but you would get a C# class out of
it...

I tried this (note the simplification of your Start and End elements to
strings - you would probably want to do this as a list of a simple type with
the precision that you require, then limit the list length). And I just used
decimal for the attributes...


Thanks for your comments,
I have made a smallest possible program that shows my problem:

#using <mscorlib.dll>
#using <System.Xml.dll>

using namespace System::Xml::Serialization;
using namespace System;

public __gc class Line {

public:
Line() {
m_start = "1 2";
m_end = "3 4";
}
[XmlElementAttributeAttribute(Form=System::Xml::Sch ema::XmlSchemaForm::Unqualified)]
__property String* get_Start() { return m_start; }
__property void set_Start(String* s) { m_start = s; }
[XmlElementAttributeAttribute(Form=System::Xml::Sch ema::XmlSchemaForm::Unqualified)]
__property String* get_End() { return m_end; }
__property void set_End(String* e) { m_end = e; }

private:

String* m_start;
String* m_end;
};

int main()
{
Line* l = new Line();
l->Start = "start";
l->End = "end";

XmlSerializer* s = new XmlSerializer(__typeof(Line));
s->Serialize(Console::Out, l, 0);

return 0;
}

This code produces the following output:

<?xml version="1.0" encoding="ibm850"?>
<Line xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<End>end</End>
<Start>start</Start>
</Line>

As you see, the End element is still ahead of the Start element. How can it
be that the equivalent program in C# gets this right (see Nigel's program)?
Would somebody who knows a bit more about this care to explain (are you
reading this Dino...)? Many thanks in advance!

--
Daniel
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 12 '05 #3

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

Similar topics

0
by: Lars | last post by:
Hello All, I have a question: is it possible to set the order of the elements of serialized object? Lets say we have Public Class Order Public Price As Decimal Private Quantity As Decimal...
5
by: Mel | last post by:
can someone post a simple javascript to change the text of the <href> for me ? thanks
13
by: Gary | last post by:
I have a table with a form consisting of several checkboxes and I'm wondering if its possible to change the table row background color on mouseover or hover and make it stay that color when the...
1
by: Daniel Lidström | last post by:
Hello, how can I control the order of which elements are serialized. For example, my class looks like: public __gc class Author { public: Author(); // get/set methods
20
by: Eric S Johansson | last post by:
I'm trying to figure out the right way to serialize a series of XMLHttpRequest transactions. I'm starting out with a table and I extract a set of elements from that table. Each set of elements is...
16
by: Giggle Girl | last post by:
Hi there, I have a nav tree similar to the XP Windows Explorer in behavior. It uses styles to underline a row on mouseover, and change the look of a row when clicked. Currently, it is working...
7
by: Giacomo | last post by:
I work on a page structured like: <h2> ... </h2> <div ="div1" class="show"> ... </div> <h2> ... </h2> <div id="div2" class="show"> ... </div> <h2> ... </h2> <div id="div3" class="show">...
11
by: free4trample | last post by:
First of all let me say that I know very little about javascript. what i need to do is to write a javascript functin which will change the background color of the table rows based on entrees in...
7
by: sj071 | last post by:
I'm little more than a novice when it comes to javascript, and this particular problem has been driving me mad for the past few days... The Problem: I have a javascript file that uses...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.