Serialization issue

C

charlyBrown

Greetings,

We migrated our application for dotnet 1.1 to dotnet 2.0 and are
generating xml files with serialization.
These generated files are thus used in a unix batch and here is the
problem

It seems that before :
Header generated in 1.1
<positions xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

And now :
Header generated in 2.0
<positions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

And the unix batch is not intelligent enough to realize that this has
no impact on the document.

Can someone tell me if there is a way to change the order of the
namespace declarations ?
It's kind of a stupid question but well, maybe there is way :)

Anyway, I'll try to investigate on my side.

Many thanks for any light shed on this
 
C

Chris Dunaway

Greetings,

We migrated our application for dotnet 1.1 to dotnet 2.0 and are
generating xml files with serialization.
These generated files are thus used in a unix batch and here is the
problem

It seems that before :
Header generated in 1.1
<positions xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

And now :
Header generated in 2.0
<positions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

And the unix batch is not intelligent enough to realize that this has
no impact on the document.

Can someone tell me if there is a way to change the order of the
namespace declarations ?
It's kind of a stupid question but well, maybe there is way :)

Anyway, I'll try to investigate on my side.

Many thanks for any light shed on this

I think you can use the XmlSerializerNamespaces class to control this:

using (StreamWriter sw = new StreamWriter(filename))
{
XmlSerializer xs = new XmlSerializer(typeof(MyType));

XmlSerializerNamespaces xn = new
XmlSerializerNamespaces();
xn.Add("xmlns:xsd",
"http://www.w3.org/2001/XMLSchema");
xn.Add("xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance");

xs.Serialize(sw, obj, xn);
}

Check the syntax because this code is from memory. It may not do
exactly what you want, but perhaps it will help.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top