all groups > dotnet xml > may 2004 >
You're in the

dotnet xml

group:

encoding="ISO-8859-1" and XML (.Net CF)



encoding="ISO-8859-1" and XML (.Net CF) ongg NO[at]SPAM w-linknospam.net
5/27/2004 1:38:27 AM
dotnet xml: Hi,
I'm using .Net CF, and I'm trying to load an XML document that has a first
line:
<?xml version="1.0" encoding="ISO-8859-1"?>

I'm loading this via XmlDocument.Load(). However, I get and XmlException
with no real good useful info:
An unhandled exception of type 'System.Xml.XmlException' occurred in
System.Xml.dll

Additional information: XmlException

It looks like the problem is with the encoding. Is there a way to have the
Xml Parser be "smart" or "forgiving" about it? Basically, if it can't
understand the encoding, then try a default encoding.
Any help appreciated.

Thanks,
Jay

Re: encoding="ISO-8859-1" and XML (.Net CF) Dare Obasanjo [MSFT]
5/27/2004 1:20:47 PM
Read the exception message. Use a try...catch around the offending code. I'm
quite sure that System.Xml understands the ISO-8859-1 encoding and the
problem lies elsewhere.

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

[quoted text, click to view]

Re: encoding="ISO-8859-1" and XML (.Net CF) ongg NO[at]SPAM w-linknospam.net
5/27/2004 10:06:14 PM
Thanks... I just checked the exception message, it is:

"The system does not support 'iso-8859-1' encoding. Line 1, position 31."

<sigh>

Is it possible to "add" an extra encoding? I don't mind just defaulting it
to utf-8 if we see iso-8859-1 (or anything else :) )!

Thanks,
Jay

[quoted text, click to view]

Re: encoding="ISO-8859-1" and XML (.Net CF) Erwin de Rijk
6/3/2004 12:11:04 AM
The System.Xml.XmlDocument does support the iso-8859-1 encoding, but the encoding attribute in the XML Declaration should be consistent with the actual encoding of the XML file (or stream). You can check the actual encoding by opening the XML file in the Visual Studio .NET environment, but instead of opening it with the default editor, use the binary editor. Maybe your file is a UTF-8 or UTF-16 encoding (you will then see a byte-order mark EF BB BF or FE FF at the beginning of the file)

You can override the used encoding using the following code (or something like it :) )

FileStream sFile = new FileStream(@"..\..\schema.xml", FileMode.Open, FileAccess.Read)
XmlParserContext xpc = new XmlParserContext(null, null, "", XmlSpace.Default, System.Text.Encoding.UTF7)
XmlTextReader xtr = new XmlTextReader(sFile, XmlNodeType.Document, xpc)

XmlDocument xDoc = new XmlDocument()
xDoc.Load(xtr)

Kind Regards
Erwin de Rij
Re: encoding="ISO-8859-1" and XML (.Net CF) ongg NO[at]SPAM w-linknospam.net
6/3/2004 2:23:39 AM
Thanks, i'll try this out!

[quoted text, click to view]
encoding attribute in the XML Declaration should be consistent with the
actual encoding of the XML file (or stream). You can check the actual
encoding by opening the XML file in the Visual Studio .NET environment, but
instead of opening it with the default editor, use the binary editor. Maybe
your file is a UTF-8 or UTF-16 encoding (you will then see a byte-order mark
EF BB BF or FE FF at the beginning of the file).
[quoted text, click to view]

AddThis Social Bookmark Button