XmlSerializer and namespace

hello !
i created class from xsd schema now i write it to xml:
-----------

XmlSerializer x = new XmlSerializer(typeof(GeneralDetailsType));
Stream s = File.Create("GeneralDetailsFileofCsharp.xml");
x.Serialize(s, gendet);
s.Close();
--------------------------
the problem is that my xml file created with the namespace field
2007-12-31
---------
i want to remove : [color=Red]xmlns="http://tempuri.org/XMLSchema.xsd">[/color]
i tried to create the serilizer with empty namespace
XmlSerializer x = new XmlSerializer(typeof(GeneralDetailsType)," ");
but it not helping me thanks !!

Comments

  • : hello !
    : i created class from xsd schema now i write it to xml:
    : -----------
    :
    : XmlSerializer x = new
    : XmlSerializer(typeof(GeneralDetailsType));
    : Stream s =
    : File.Create("GeneralDetailsFileofCsharp.xml");
    : x.Serialize(s, gendet);
    : s.Close();
    : --------------------------
    : the problem is that my xml file created with the namespace field
    : 2007-12-31
    : ---------
    : i want to remove :
    : [color=Red]xmlns="http://tempuri.org/XMLSchema.xsd">[/color]
    : i tried to create the serilizer with empty namespace
    : XmlSerializer x = new XmlSerializer(typeof(GeneralDetailsType),"
    : ");
    : but it not helping me thanks !!

    I ran into the same problem. I'm still working it out, but here is what I found out:

    1. Look at the XmlSerializer constructor. There is an overload that allows you to set a default namespace
    2. Look at the XmlWriterSettings class and in particular the ConformanceLevel property. You have to set it to Fragment or Auto or otherwise the Serializer will complain the Xml it is generating is not valid.
    3. The XmlSerializer constructor has another overload tha takes XmlAttributeOverrides. I think you can use that to override the namespace.
    4. Look at the XmlWriterNamespace class. It allows you to add new namespaces to your writer.

    Good luck !
  • Here is what I ended up doing:

    [code]XmlSerializer mySerializer = new XmlSerializer(typeof(Marker), "");
    XmlSerializerNamespaces myNameSpc = new XmlSerializerNamespaces();
    myNameSpc.Add("", "");[/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion