xmlguy,
1) What's args[0] in your example? Does it contain any Xml? In that case you
first have to pass that sting off to a StringReader. If it's a path to a
file then it's OK.
You have to actually start reading the contents of the XML document. You do
this by calling the Read() method for the first time. This sample code works
for me:
string xml = "<foo>bar</foo>";
XmlTextReader reader = new XmlTextReader( new StringReader( xml ) );
//go to the first node
reader.Read();
System.Diagnostics.Debug.WriteLine( reader.Encoding.EncodingName );
2) All strings object in the framework are unicode encoded. You can work
with the various encoding classes in System.Text.Encoding to create byte[]s
and MemoryStreams that contain text encoded in a different encoding scheme.
You cannot change the encoding of string objects.
--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor
"xmlguy" <xm****@yahoo.com> wrote in message
news:0a****************************@phx.gbl...
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