473,396 Members | 1,975 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,396 software developers and data experts.

XmlDocument and iso-8859-1 Encoding

Hi all,
I have an application loading xml-documents. The purpose is just to load the
document and do some processing. The documents is generated by external
vendors outside my company.
Some of the vendors, however, delivers the documents encoded as iso-8859-1 -
the document root looks like this:
<?xml version="1.0" encoding="iso-8859-1"?>
....

In my application which is written in C# I use the following code to load
the document:
XmlDocument xmlInvoiceDocument = new XmlDocument();
xmlInvoiceDocument.Load(filename);

When the file is UTF-8-encoded this works perfectly, but when loading a
iso-8859-1 document it throws an XmlException with the message: "The data at
the root level is invalid. Line 1, position 44.".

Do I have any options in changing the encoding of the XmlDocument-object
before loading(I think the exception is caused by .NET not knowing the fact
that the file is iso-8859-1 encoded) ??

Does anyone have a clue ?

Thanks in advance,
Mogens Nielsen
Elbek & Vejrup A/S

Nov 12 '05 #1
4 3273


Mogens Nielsen - Elbek & Vejrup A/S wrote:

I have an application loading xml-documents. The purpose is just to load the
document and do some processing. The documents is generated by external
vendors outside my company.
Some of the vendors, however, delivers the documents encoded as iso-8859-1 -
the document root looks like this:
<?xml version="1.0" encoding="iso-8859-1"?>
...

In my application which is written in C# I use the following code to load
the document:
XmlDocument xmlInvoiceDocument = new XmlDocument();
xmlInvoiceDocument.Load(filename);

When the file is UTF-8-encoded this works perfectly, but when loading a
iso-8859-1 document it throws an XmlException with the message: "The data at
the root level is invalid. Line 1, position 44.".


It is likely that while the XML declaration in the encoding attribute
suggests the file is iso-8859-1 encoded in reality it is not and thus
the parser gives an error as it is supposed to do.
Have you parsed that file with other XML parsers, for instance loaded it
in IE 6? Do they parse it without problems?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
I'm not able to load the file in IE 6 either. If I delete the
encoding-statement, however, it loads fine... Looks like you're right
regarding the file encoding. The vendor have a problem then...
Do you know a way to determine the file encoding before loading it in code?
Alternatively just a way to determine it in Windows ?

/Mogens

"Martin Honnen" wrote:


Mogens Nielsen - Elbek & Vejrup A/S wrote:

I have an application loading xml-documents. The purpose is just to load the
document and do some processing. The documents is generated by external
vendors outside my company.
Some of the vendors, however, delivers the documents encoded as iso-8859-1 -
the document root looks like this:
<?xml version="1.0" encoding="iso-8859-1"?>
...

In my application which is written in C# I use the following code to load
the document:
XmlDocument xmlInvoiceDocument = new XmlDocument();
xmlInvoiceDocument.Load(filename);

When the file is UTF-8-encoded this works perfectly, but when loading a
iso-8859-1 document it throws an XmlException with the message: "The data at
the root level is invalid. Line 1, position 44.".


It is likely that while the XML declaration in the encoding attribute
suggests the file is iso-8859-1 encoded in reality it is not and thus
the parser gives an error as it is supposed to do.
Have you parsed that file with other XML parsers, for instance loaded it
in IE 6? Do they parse it without problems?

--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #3


Mogens Nielsen - Elbek & Vejrup A/S wrote:

Do you know a way to determine the file encoding before loading it in code?
Alternatively just a way to determine it in Windows ?


The XML declaration requires the encoding attribute for anything but
UTF-8 and UTF-16 as the encoding of a file can in general not be
determined or inferred by looking at the bytes. So there is no way to
determine that.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #4
Okay that's a pity.
Thank you very much for your answers - they are very much appreciated...

"Martin Honnen" wrote:


Mogens Nielsen - Elbek & Vejrup A/S wrote:

Do you know a way to determine the file encoding before loading it in code?
Alternatively just a way to determine it in Windows ?


The XML declaration requires the encoding attribute for anything but
UTF-8 and UTF-16 as the encoding of a file can in general not be
determined or inferred by looking at the bytes. So there is no way to
determine that.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Nov 12 '05 #5

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

Similar topics

2
by: Ayende Rahien | last post by:
Serious problem I'm using Chris Lovett's SgmlReader class SgmlReader sr = new SgmlReader(); XmlDocument xdoc = new XmlDocument(); sr.DocType = "HTML"; sr.InputStream = new...
5
by: KathyB | last post by:
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an...
1
by: Martin Honnen | last post by:
With both .NET 1.0 and 1.1 I have found the following strange behaviour where System.Xml.XmlDocument.LoadXml doesn't throw an error when parsing a text node with a character reference to an invalid...
4
by: Robert Rossney | last post by:
I'm trying to send and receive XmlDocument objects using the System.Messaging.dll functions. The code I've written follows, as best I can tell, the methodology used in the sample code for the...
2
by: Dave | last post by:
Hi, Is there an easier way to pull a subset of nodes from one XmlDocument to another? I have the code below but would like to know if there is a more streamlined method. Thanks, Dave ...
8
by: pete | last post by:
Hi there, Can someone explain to me why I can't bind to an XmlDocument but I can bind to an XmlNodeList. It's my understanding that they both implement the IEnumerable interface which is...
1
by: Peter Nofelt | last post by:
Hey All, I'm running into this issue with parsing through an xml document by tag name. Below is an example xml document: File Name: things.xml <things> <people> <name>Peter</name>
1
by: David | last post by:
I need to find a good online resource which teaches the use of the XmlDocument framework in more depth than is covered in MS's online doc. I need to create a multi-level XML document like the one...
5
by: Rob Panosh | last post by:
Hello, I am trying to create a xmlDocument from as dataset. My code is listed below. All seems to go well until xmlDocument.Load(CType(ms, System.IO.Stream)) ... I keep getting the following...
2
by: John Smith | last post by:
I'm writing webervice client using .Net 2.0. I have this class: public class MyWebService : SoapHttpClientProtocol { public XmlDocument validate(string url, XmlDocument xmlDocument) {...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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.