Jump to content

  • Log In with Google      Sign In   
  • Create Account


[C#] XmlSerializer Why are attributes before namespace?!


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Samurai Jack   Members   -  Reputation: 202

Like
0Likes
Like

Posted 30 January 2012 - 04:43 AM

Hello!

I'm writing a Collada EXPOTER using serializable classes in conjunction with
the XmlSerializer so please do not post answers about XmlDocument.

Here is my class header:
[Serializable]
[XmlRoot(ElementName = "COLLADA", IsNullable = false)]  
public class DaeModel
{
private const string DefaultNamespace = @"http://www.collada.org/2005/11/COLLADASchema";
private string _version = "1.4.1";
[XmlAttributeAttribute(AttributeName = "version", Namespace = DefaultNamespace)]
public string Version
{
  get { return _version; }
  set { _version = value; }
}

I would like to achieve this:
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">

But C# gives me this:
<COLLADA version="1.4.1" xmlns="http://www.collada.org/2005/11/COLLADASchema">

Why is the version in front of the namespace?! How can I put the version behind the xmlns?

Here is my save code:
public void Save(string fileName)
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.Encoding = Encoding.UTF8;
settings.OmitXmlDeclaration = false;
XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add(string.Empty, DefaultNamespace);
XmlWriter writer = XmlWriter.Create(Console.Out, settings);
XmlSerializer serializer = new XmlSerializer(GetType(), DefaultNamespace);
serializer.Serialize(writer, this, namespaces);
}

Thank you in advance!

Sponsor:

#2 Nikster   Members   -  Reputation: 178

Like
0Likes
Like

Posted 30 January 2012 - 05:19 AM

Have you tried putting the namespace name on the root element rather than the attribute?

EDIT:- I removed my previous post because my eyes failed to read most of your post, Monday morning blues :)

#3 Samurai Jack   Members   -  Reputation: 202

Like
0Likes
Like

Posted 30 January 2012 - 05:20 AM

The namespace is acctualy ignored or screwed when put in the XmlRoot. Every element gets this: q1:elementname.
It' driving me nuts.

#4 Nikster   Members   -  Reputation: 178

Like
0Likes
Like

Posted 30 January 2012 - 06:46 AM

Hrm, sorry then I've no idea, I've never used other attributes alongside xmlns, however with attributes I wouldn't have thought ordering of attributes to be an issue when parsing the actual data, is this something that's causing a problem with the data you're saving an is being used by something else or is it just an annoyance visually?

XmlSerializer serializer = new XmlSerializer(GetType(), DefaultNamespace);

This is the line that appears to be appending the namespace name itself to the attribute list and there seems to be no way of specifying where it will go.

So sorry I can;t help but maybe someone else knows of somthing.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS