473,654 Members | 3,078 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlTextWriter Encoding and Serialization

Two questions:
I've a XmlTextWriter that I want to use to build a string in memory.
However, when I'm using a StringWriter, the xml comes out at UTF-16, which
isn't good for me.
Currently, I solved the problem by using XmlDocument, but it seems a waste
to use that if I can use XmlWriter.
I tried to spesify the encoding, and then it complained about needing a
Stream and not a TextWriter.
I *must* have this in memory, writing to file is not an option in this case.
I tried using MemoryStream, but I can't seem to get the Xml out.
How do I do this?

Second question:
I've a type that was built from xsd schema, when I try to serialize it I get
an error (need to add XmlInclude), why?
The first two lines where added by xsd.exe, the third I added, but I still
get this error, why? And how to solve it?
I thought that if I define my type as xsd schema I wouldn't have a problem
serializing it, which was the whole point in doing this.
[System.Xml.Seri alization.XmlTy peAttribute(Nam espace="http://tempuri.org/Rss
Feed.xsd")]

[System.Xml.Seri alization.XmlRo otAttribute(Nam espace="http://tempuri.org/Rss
Feed.xsd", IsNullable=fals e)]
[System.Xml.Seri alization.XmlIn clude(typeof(Fe ed))]
Nov 12 '05 #1
1 3159
"Ayende Rahien" <Ay****@no.spam > wrote in message
news:e3******** ******@TK2MSFTN GP10.phx.gbl...
Two questions:
I've a XmlTextWriter that I want to use to build a string in memory.
However, when I'm using a StringWriter, the xml comes out at UTF-16, which
isn't good for me.
Currently, I solved the problem by using XmlDocument, but it seems a waste
to use that if I can use XmlWriter.
I tried to spesify the encoding, and then it complained about needing a
Stream and not a TextWriter.
I *must* have this in memory, writing to file is not an option in this case. I tried using MemoryStream, but I can't seem to get the Xml out.
How do I do this?


An interesting discussion of this can be found here:
http://weblogs.asp.net/rmclaws/posts/22080.aspx#24141

--
Bryant
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
16767
by: Adam Rothberg | last post by:
The following code sample should produce a valid xml file to the console. However, when I try this in C# (Visual Studio 2003, 1.1 Framework), there is an extra questionmark preceding the rest of the content. MemoryStream ms = new MemoryStream(); XmlTextWriter xtw = new XmlTextWriter(ms, Encoding.UTF8); xtw.Namespaces = false; xtw.Indentation = 5; xtw.Formatting = Formatting.Indented;
5
9157
by: Jain, Pranay Kumar | last post by:
Hello Everyone, I have written a simple app. that converts the dataset into excelspreadsheet. The App. uses the following architecture. First it generates the dataset with corresponding datatables(each datatable represents a worksheet).It uses an Xslt file to do the transformation of the xml (generate from dataset) and write the output xml into a xmltextwriter. The App converts the data into excel with almost all of the formatting
3
5956
by: Magnus | last post by:
can anyone help me on how to create and manipulate a xmttextwriter without having to craete a physical file. I have an application that should return data in xml. But I do not want to create a file and then delete it. /Magnus
4
11514
by: H Lee | last post by:
Hi, I'm an XML newbie, and not sure if this is the appropriate newsgroup to post my question, so feel free to suggest other newgroups where I should post this message if this is the case. I'm having issues using XmlTextWriter, saving it out to a file with UTF8 encoding, and seeing "dirty", or "human unreadable" characters show up *right before* the XML declaration. I need to have the XML declaration state "encoding = utf-8", but also...
3
3440
by: K Rege | last post by:
Hi there, I tried to implement a little XML-EchoServer using Sockets and XmlTextWriter/Reader. However the server hangs while reading the input from the client (wr.Flush() seams not to work). I could make it run by using s.Send(new byte); instead of flush, but this cannot be the solution. Is there a better work around or fix to this problem? I use 1.1 with SP1, so the earlier posting do not apply. Merry Christmas and thanks
2
7198
by: Josh Newman | last post by:
I'm using the XMLTextWriter to create an XML document. I do not want the encoding attribure in the XML file. Instead of: <?xml version="1.0" encoding="utf-8"?> I want: <?xml version="1.0"?> Code extract:
5
4992
by: Robert Dickow | last post by:
Hi, My XML files created with XmlTextWriter routines has been resulting in working files, but they include three bytes of garbage at the start of the file. The bytes are: $EF $BB $BF (I think it always outputs these) I am using VS 2002 and C#.
2
3384
by: Mori | last post by:
I am using the following code to manufactue xml using xmltextwriter. The xml is okay except for the extra set of start document and the outer <string> element. Where do they come from and how do I keep those from being written? <?xml version="1.0" encoding="utf-8" ?> - <string xmlns="http://www.Employee.com/abc/"> <?xml version="1.0" encoding="utf-8" ?> - <Services xmlns:xsd="http://www.w3.org/2001/XMLSchema"...
1
2881
by: hharry | last post by:
hi all i have the following class: <Serializable()> _ Public Class MVR_Inputs Public FirstName As String Public MiddleName As String Public LastName As String Public Suffix As String
0
8372
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8285
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8814
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8475
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1592
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.