473,480 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

error getting the encoding name from an XmlTextReader

XmlTextReader myXmlReader = new XmlTextReader(args[0]);
string en = myXmlReader.Encoding.EncodingName;
//Console.WriteLine(x);

Error:

Unhandled Exception: System.NullReferenceException: Object
reference not set to
an instance of an object.

HOW CAN I GET THE ENCODING NAME ? Basically determine the
encoding type.

Also How can I "set" an application wide Encoding ? I want
all modules and everything to stick to and conform to UTF-
8.

But somehow some methods automatically go to UTF-16
Nov 11 '05 #1
4 3376
xmlguy wrote:
XmlTextReader myXmlReader = new XmlTextReader(args[0]);
string en = myXmlReader.Encoding.EncodingName;
//Console.WriteLine(x);

Error:

Unhandled Exception: System.NullReferenceException: Object
reference not set to
an instance of an object.

HOW CAN I GET THE ENCODING NAME ? Basically determine the
encoding type.
You have to call Read() method at least once if you want to get Encoding
property. That's because XmlReader is pull-mode parser - it's your
responsibbility to call its Read() method to force it to read XML.
Encoding is stored in XML declarartion, which is always the very first
line in XML, so single Read() call would be enough to read it.
Also How can I "set" an application wide Encoding ? I want
all modules and everything to stick to and conform to UTF-
8.

Elaborate please, what do you mean.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
Is there any way to specify that all modules or
fns/methods in a given application follow only a single
encoding e.g. UTF-8

Because somehow I input my XML as UTF-8 and it
automatically comes out ast UTF-16.

How can i ensure application-wide setting/configuration
that it stick to one format.
-----Original Message-----
xmlguy wrote:
XmlTextReader myXmlReader = new XmlTextReader(args[0]);
string en = myXmlReader.Encoding.EncodingName;
//Console.WriteLine(x);

Error:

Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.

HOW CAN I GET THE ENCODING NAME ? Basically determine the encoding type.
You have to call Read() method at least once if you want

to get Encodingproperty. That's because XmlReader is pull-mode parser - it's yourresponsibbility to call its Read() method to force it to read XML.Encoding is stored in XML declarartion, which is always the very firstline in XML, so single Read() call would be enough to read it.
Also How can I "set" an application wide Encoding ? I want all modules and everything to stick to and conform to UTF- 8.

Elaborate please, what do you mean.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

.

Nov 11 '05 #3
xmlguy wrote:
Is there any way to specify that all modules or
fns/methods in a given application follow only a single
encoding e.g. UTF-8

Because somehow I input my XML as UTF-8 and it
automatically comes out ast UTF-16.

How can i ensure application-wide setting/configuration
that it stick to one format.


I believe that's unfeasible and as well as quite unusual, so there is no
such functionality in .NET. Some situations doesn't allow UTF-8
altogether, e.g. strings are always UTF-16 encoded.
You have to take care of encoding issues on yours own. Beware of
implicit recodings.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #4
Here's an interesting article discussing Unicode and character sets

http://www.joelonsoftware.com/articles/Unicode.html

Eirik M.

"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
xmlguy wrote:
Is there any way to specify that all modules or
fns/methods in a given application follow only a single
encoding e.g. UTF-8

Because somehow I input my XML as UTF-8 and it
automatically comes out ast UTF-16.

How can i ensure application-wide setting/configuration
that it stick to one format.


I believe that's unfeasible and as well as quite unusual, so there is no
such functionality in .NET. Some situations doesn't allow UTF-8
altogether, e.g. strings are always UTF-16 encoded.
You have to take care of encoding issues on yours own. Beware of
implicit recodings.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #5

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

Similar topics

4
2381
by: Bill Cohagan | last post by:
I'm writing a console app in c# and am encountering a strange problem. I'm trying to use redirection of the standard input stream to read input from a (xml) file. The following code snippet is from...
0
1094
by: Sangeetha Nagaraj | last post by:
Hi, I am writing a program to validate a XML file and i am getting an error. Here is my Code, and i get an error at "args.Exception" ("The 'urn:books:catalog' element is not declared. An error...
0
442
by: SqlJunkies User | last post by:
I have pretty same problem with XmlDocument.Load(). It seems to appear after KB834623 hotfix installed. Here is the information to reproduce error: Technical info: • Windows XP Professional SP1...
1
3348
by: stuart dent via .NET 247 | last post by:
XML validation error. Help required If anyone can help me, thankyou, thankyou... When I run this code code I get this error: The data at the root level is invalid. Line 1, position 39. I...
2
3639
by: ecomputerdelicacy | last post by:
Compact Framework SP3 (and I think also SP2 and SP1) XmlTextReader does not handle !DOCTYPE and (maybe?) rdf elements. How can I get the XmlTextReader to read these without issuing a...
2
1363
by: Michael | last post by:
Hi All, I have something going wrong with the XmlTextReader. I have a function that reads the following XML example. For some reason the code is only getting two of the 3 Values elements. Here is...
6
31955
by: jasn | last post by:
Hello I am getting the following error message when I try and send an XML sting to a web service, I read somewhere that most web services prefer ascii and some throw errors when using unicode so...
2
2985
by: Cesar | last post by:
Hello, I've developed a .NET C# web service; which has one method named, let's say, upload_your_data. This method has one parameter ( string your_data). The value that this parameter will...
2
4424
by: Manikrag | last post by:
Hi All, I am getting error while am loading RSS Stream in XMLDocument object. The error is as follows. "System.Xml.XmlException: '', hexadecimal value 0x19, is an invalid character. Line 18,...
0
7055
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
7103
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...
1
6758
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
7010
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
5362
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
4499
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...
0
3011
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...
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
203
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...

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.