473,224 Members | 1,319 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 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 2422
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ken Lindner | last post by:
We have a report based on a query that is called from a form. Nothing too special here. The query has 3 coulmns that are populated directly from values entered into entry fields on the form...
8
by: Hardy Wang | last post by:
Hi: Is it possible for me to create/open web application from remote machine other than port 80? And create application directly under virtual web site instead of creating a virtual directory?...
2
by: louise raisbeck | last post by:
hi, i am trying to get to a point where i can use intellisense. i have everything else sorted apart from my codebehind. Is it me or does .NET seem really biased towards vb.net? even though i have...
1
by: Prad Bok via .NET 247 | last post by:
(Type your message here) -------------------------------- From: Prad Bok I have a web page that takes long time(more than 3 minutes) tofinish. I am running IIS6 on windows 2003 server. I...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
1
by: wolfgang wagner | last post by:
hi all! i'm trying to convert my former asp.net 1.1 application to a asp.net 2.0 application. everything runs fine expect the logging with log4net. in my development environment it logs to the...
0
by: Vaibhav Goel | last post by:
Hi, We have made a windows product that has several crystal reports developed in dotnet framework 1.1, now certain customers dont want 1.1 and have framework 2.0 installed only.All the reports in...
1
by: Nilesh Thakur | last post by:
Hi all, i am working on Dotnet want to create Scheduler in DotNet using C#... how can i do this ?? if any one having idea then pls tell with some sample code .. thanx in advance, thanx and...
7
by: K Viltersten | last post by:
As i noticed, there's no built-in facility for working with SFTP in DotNet. So, i'd like to learn how to build that up. When i went googling for knowledge, i only get a ton of hits on tutorials...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.