469,349 Members | 1,699 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,349 developers. It's quick & easy.

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

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
Nov 12 '05 #1
6 10348
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.

<on**@w-linknospam.net> wrote in message
news:OY*************@tk2msftngp13.phx.gbl...
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

Nov 12 '05 #2
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

"Dare Obasanjo [MSFT]" <da***@online.microsoft.com> wrote in message
news:40********@news.microsoft.com...
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.
<on**@w-linknospam.net> wrote in message
news:OY*************@tk2msftngp13.phx.gbl...
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


Nov 12 '05 #3
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
Info Support
Nov 12 '05 #4
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
Info Support
Nov 12 '05 #5
Thanks, i'll try this out!

"Erwin de Rijk" <erwinr@-nospam-infosupport.com> wrote in message
news:12**********************************@microsof t.com...
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 Rijk
Info Support

Nov 12 '05 #6
Thanks, i'll try this out!

"Erwin de Rijk" <erwinr@-nospam-infosupport.com> wrote in message
news:12**********************************@microsof t.com...
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 Rijk
Info Support

Nov 12 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.