473,405 Members | 2,354 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,405 software developers and data experts.

Auto change in Encoding - XmlReader, XmlDocument, StringWriter

This is part of the application that reads XML from file
(that has UTF-8) into an XmlTextReader

XmlTextReader myXmlReader = new XmlTextReader(args[0]);

It then instantiates an object/class instance Render where
this constructor gets called with "that" XmlReader.

public Render(XmlReader cleanxmldoc)

{

XmlDocument XmlDoc = new XmlDocument();
System.IO.StringWriter sw = new System.IO.StringWriter();

/*
sw.Encoding.Equals(System.Text.Encoding.UTF8);
string dd = sw.Encoding.GetEncoder().ToString();
Console.WriteLine(dd);
sw.Encoding.EncodingName.Equals("UTF8");
sw.Encoding.GetDecoder();
dd = sw.Encoding.GetEncoder().ToString();
*/

XmlDoc.Load(cleanxmldoc);
XmlDoc.Save(sw);
xstring = sw.ToString();

(When I look at the output somewhere between in these
lines it went from UTF8 to UTF 16) How I dont know?
How can I detect where ? and How can I control it.

I have commented some lines above, they compile but dont
do much in the detection or control that I want.
..............

}
Nov 11 '05 #1
2 14830
Strings in the .NET Framework are always encoded in UTF-16. A good
description of the reasons for the problem you are facing are at
http://weblogs.asp.net/rmclaws/posts/22080.aspx

--
This posting is provided "AS IS" with no warranties, and confers no rights.
"xmlguy" <xm****@yahoo.com> wrote in message
news:05****************************@phx.gbl...
This is part of the application that reads XML from file
(that has UTF-8) into an XmlTextReader

XmlTextReader myXmlReader = new XmlTextReader(args[0]);

It then instantiates an object/class instance Render where
this constructor gets called with "that" XmlReader.

public Render(XmlReader cleanxmldoc)

{

XmlDocument XmlDoc = new XmlDocument();
System.IO.StringWriter sw = new System.IO.StringWriter();

/*
sw.Encoding.Equals(System.Text.Encoding.UTF8);
string dd = sw.Encoding.GetEncoder().ToString();
Console.WriteLine(dd);
sw.Encoding.EncodingName.Equals("UTF8");
sw.Encoding.GetDecoder();
dd = sw.Encoding.GetEncoder().ToString();
*/

XmlDoc.Load(cleanxmldoc);
XmlDoc.Save(sw);
xstring = sw.ToString();

(When I look at the output somewhere between in these
lines it went from UTF8 to UTF 16) How I dont know?
How can I detect where ? and How can I control it.

I have commented some lines above, they compile but dont
do much in the detection or control that I want.
.............

}

Nov 11 '05 #2
cool. exactly what i needed
-----Original Message-----
Strings in the .NET Framework are always encoded in UTF- 16. A gooddescription of the reasons for the problem you are facing are athttp://weblogs.asp.net/rmclaws/posts/22080.aspx

--
This posting is provided "AS IS" with no warranties, and confers no rights.

"xmlguy" <xm****@yahoo.com> wrote in message
news:05****************************@phx.gbl...
This is part of the application that reads XML from file
(that has UTF-8) into an XmlTextReader

XmlTextReader myXmlReader = new XmlTextReader(args[0]);

It then instantiates an object/class instance Render where this constructor gets called with "that" XmlReader.

public Render(XmlReader cleanxmldoc)

{

XmlDocument XmlDoc = new XmlDocument();
System.IO.StringWriter sw = new System.IO.StringWriter ();
/*
sw.Encoding.Equals(System.Text.Encoding.UTF8);
string dd = sw.Encoding.GetEncoder().ToString();
Console.WriteLine(dd);
sw.Encoding.EncodingName.Equals("UTF8");
sw.Encoding.GetDecoder();
dd = sw.Encoding.GetEncoder().ToString();
*/

XmlDoc.Load(cleanxmldoc);
XmlDoc.Save(sw);
xstring = sw.ToString();

(When I look at the output somewhere between in these
lines it went from UTF8 to UTF 16) How I dont know?
How can I detect where ? and How can I control it.

I have commented some lines above, they compile but dont
do much in the detection or control that I want.
.............

}

.

Nov 11 '05 #3

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

Similar topics

1
by: Neil Guyette | last post by:
Hi, All, I'm trying to take an xmldocument and output it to html (email). Everything seems to work when I capture the XmlDocument to a StringWriter and past that to the Mail objects body. When...
5
by: Jiho Han | last post by:
I do a transform of an xml document into another xml using XslTransform. In my xsl file, I specify using <xsl:output encoding="utf-8"/>. However, when my transform is done, the resulting xml is in...
3
by: Fahad Ashfaque | last post by:
Hi, I found the XSL Transformation through .NET too complex. The most simplest overload of System.Xml.Xsl.XslTransform is Transform(inputfile, outputfile), but this saves the result into file. I...
0
by: terrorix | last post by:
Hi, I Have this sql select(MS SQL): select a.ID, b.ID from Table as a left outer join table AS b
4
by: Bob | last post by:
Hi Need to produce a Doc with no encoding info. Is there anyway of doing this? Thanks Bob i.e. <?xml version=\"1.0\" ?>
10
by: Thirsty Traveler | last post by:
All of the XmlReader examples assume that the XmlDocument is being read from a file. However, I would like to use it with an XmlDocument passed as a method parameter, but am not sure how. Any...
2
by: JM | last post by:
Hello, Most of the examples I've seen with XMLReaders, serialization, etc,. involve a text file on a file system. Does anybody have a start to finish VB.NET example of reading an XML Document...
3
by: Matt | last post by:
I have a problem where I am working with extended character sets in XML but I have also found that any time I work with a translation or internally generated Xml document I get the dreaded message,...
3
by: mortb | last post by:
1. How do I determine which encoding a xmldocument or xmlreader uses when opening a document? I'm not just talking about the <?xml encoding="utf-8"?attribute, but the actual encoding of the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.