Hi,
I am having trouble serializing an object in dotnet 2.0.
I am using theis method
public static string Serialize(object o, string defaultNamespace)
{
//create empty namespace to prevent namespace output
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", defaultNamespace);
//create serializer
XmlSerializer ser = new XmlSerializer(o.GetType());
using(StringWriter writer = new StringWriter())
{
//use custom writer to prevent root 'xml' tag output
XmlNoPrefixTextWriter xwriter = new XmlNoPrefixTextWriter(writer);
xwriter.Formatting = Formatting.None;
ser.Serialize(xwriter, o, ns);
return writer.ToString();
}
}
In dotnet 1.1. the output I get is <TestDTO
xmlns="http://House/Test"><X>Hi</X><Y>There</Y></TestDTO>
In dot net 2.1 the output I get is <TestDTO><X>Hi</X><Y>There</Y></TestDTO>
Basically I am missing the namespace reference in the xml. Is there a way to
fix this. What changes do I need to make.
Thanks
Rahul Aggarwal