473,397 Members | 2,084 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,397 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 2426
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.