471,086 Members | 1,102 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,086 software developers and data experts.

XmlSerializerNamespaces not working the same in dotnet 2.0 as

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
Aug 11 '06 #1
1 2326
Hello Rahul,

What does that XmlNoPrefixTextWriter do?
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

Aug 11 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Hardy Wang | last post: by
2 posts views Thread by louise raisbeck | last post: by
1 post views Thread by Prad Bok via .NET 247 | last post: by
8 posts views Thread by jojobar | last post: by
1 post views Thread by wolfgang wagner | last post: by
1 post views Thread by Nilesh Thakur | last post: by
7 posts views Thread by K Viltersten | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.