Removing the xsd + xsi namespaces added during Serialization

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I have put together a serializable object used to maintain the Web.config
file and am having trouble because the Serialization process adds xsd and xsi
namespaces to the root element. This causes the web-site to crash.

Can anyone tell me if there is a cleaner way (attributes on the
XmlRootAttribute?) that will stop the serialization process from adding these
namespaces?

I can always open the text file and remove the text from it, but would
prefer a more 'documented' approach that simply doesn't put them there in the
first place.

Thanks in advance,
Rob
 
Hello Robert,

I'm assuming you're using the XmlSerializer. Try this:

[C#]
StringWriter sw = new StringWriter();
XmlTextWriter tw = new XmlTextWriter(sw);
XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();
xsn.Add(String.Empty, String.Empty);

XmlSerializer serializer = new XmlSerializer(typeof(MyObject));
serializer.Serialize(tw, object, xsn);

// at this point, sw.ToString() has the namespace free results

I know its not with attributes, but it does accomplish the goal.
 
Back
Top