473,386 Members | 1,757 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,386 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 2288
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.