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

XmlReaderSettings Conflict with UTF-16?

Hi,

Here's my problem code:

....
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Document;
settings.CheckCharacters = false;
settings.IgnoreComments = true;
settings.IgnoreProcessingInstructions = true;
settings.IgnoreWhitespace = true;
settings.ProhibitDtd = false;
System.IO.FileStream stream = new System.IO.FileStream(path,
FileMode.Open, FileAccess.Read, FileShare.Read);
XmlReader reader = XmlReader.Create(stream, settings);
XmlDocument myDocument = new XmlDocument();
try
{
myDocument.Load(reader);
}
catch (Exception e)
{
....

The code works if "path" refers to a UTF-8 encoded XML file. If it
refers to a UTF-16 encoded file, myDocument.Load(reader) throws an
exception. Also, if I replace myDocument.Load(reader) with
myDocument.Load(path), the code works for both UTF-8 and UTF-16, but I
can't do that because I need the XmlReaderSettings.

The message and stack trace are:

An error has occurred while opening external DTD 'file:///C:/Documents
and Settings/myName/folder1/.../folder6/folder7/someFileName.dtd':
Could not find a part of the path 'C:\\Documents and Settings\\myName\
\folder1\\...

at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.DtdParserProxy_PushEx ternalSubset
(String systemId, String publicId)
...

That's not the correct path to the DTD. The path is relative to the
location of the XML file.

The XML contains:

<!DOCTYPE myType SYSTEM "folder6/folder7/someFileName.dtd">

This exact tag appears in UTF-8 encoded XML files in an identical
directory structure, and they don't produce this error.

Any help would be much appreciated.

Thanks,
Daniel Sheiner
Nov 13 '08 #1
4 4072
(okay, I used &lt; and &gt; there thinking they'd be turned into < and
>. The XML *actually* contains:
<!DOCTYPE myType SYSTEM "folder6/folder7/someFileName.dtd">

Sorry if this caused any confusion.)

Nov 13 '08 #2
Daniel S wrote:
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Document;
settings.CheckCharacters = false;
settings.IgnoreComments = true;
settings.IgnoreProcessingInstructions = true;
settings.IgnoreWhitespace = true;
settings.ProhibitDtd = false;
System.IO.FileStream stream = new System.IO.FileStream(path,
FileMode.Open, FileAccess.Read, FileShare.Read);
XmlReader reader = XmlReader.Create(stream, settings);
Why don't you simply use
XmlReader reader = XmlReader.Create(path, settings);
?
XmlDocument myDocument = new XmlDocument();
try
{
myDocument.Load(reader);
}
catch (Exception e)
{
...

The code works if "path" refers to a UTF-8 encoded XML file. If it
refers to a UTF-16 encoded file, myDocument.Load(reader) throws an
exception. Also, if I replace myDocument.Load(reader) with
myDocument.Load(path), the code works for both UTF-8 and UTF-16, but I
can't do that because I need the XmlReaderSettings.

The message and stack trace are:

An error has occurred while opening external DTD 'file:///C:/Documents
and Settings/myName/folder1/.../folder6/folder7/someFileName.dtd':
Could not find a part of the path 'C:\\Documents and Settings\\myName\
\folder1\\...
That message does not look in any way to be related to the encoding of
the XML document.

This exact tag appears in UTF-8 encoded XML files in an identical
directory structure, and they don't produce this error.
I will try to reproduce that, can't currently believe that the encoding
should have any effect on URL resolution.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 13 '08 #3
Martin Honnen wrote:
>This exact tag appears in UTF-8 encoded XML files in an identical
directory structure, and they don't produce this error.

I will try to reproduce that, can't currently believe that the encoding
should have any effect on URL resolution.
I have tried to reproduce that, using an UTF-8 encoded file and an
UTF-16 encoded file, both referencing the same DTD file in a
subdirectory. I am not able to reproduce that error so check your file
paths, the error very much sounds as if there is indeed a path wrong.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 13 '08 #4
Why don't you simply use
XmlReader reader = XmlReader.Create(path, settings);
?
Good question. I rearranged the code to simplify my earlier post.
The stream was actually created in its own function:

public static System.IO.FileStream AdvanceStreamToStartXml(string
path)
{
System.IO.FileStream stream = new System.IO.FileStream(path,
FileMode.Open, FileAccess.Read, FileShare.Read);
return AdvanceStreamToStartXml(stream);
}

My eyes played a trick on me, transforming that return statement to
"return stream;" (I'm obviously not the original author of this
code). In AdvanceStreamToStartXml(stream), we're advancing the start
position of the FileStream to just past the doctype tag (that
validation is supposed to happen elsewhere), and we do so assuming
single-byte encoding, which I believe is the root of this problem.

Thanks!!!!!!
-Daniel
Nov 13 '08 #5

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

Similar topics

0
by: Adam | last post by:
Hi I had Ruby 1.6.8-8 for Windows installed on my WinXP Pro machine prior to installing Python 2.3. After installing Python 2.3, I tried to <----- screen output of python interactive command...
2
by: news.dd.chalmers.se | last post by:
Hi I use a library called system-c i a project that likes to be compiled single-threaded and I would like to add shared memory capability. I found some nice code that works fine but only if...
2
by: pawel.pabich | last post by:
Hajo, I want to validate xml against DTD but I am not able to load DTD schema. My code looks like that: XmlReaderSettings settings = new XmlReaderSettings(); settings.ProhibitDtd = false;...
0
by: Jen | last post by:
My main question: "How can I get a TextReader or Stream object from an existing XmlReader?". Read on for more: I have an existing XmlReader. Let's call it reader1. I'm creating another reader,...
0
by: Simon Ovens | last post by:
Hi im trying to read a news feed that is generated from an aspx page on my server but it comes up with and unauthrised error. I have changed the perimssions on the aspx news feed generator to no...
12
by: Logos | last post by:
Yes, eval is a tool of the devil and I'll burn for using it. However, in this instance it's quite handy and I'm quite lazy. So, here's a weird one, and I'm wondering if anyone has a workaround....
2
by: ba.hons | last post by:
Hi I have been tring to use some of the following classes which are new in ..net version 2 from what i have read on the MSDN the following should be supported XmlReaderSettings settings = new...
2
by: Techno_Dex | last post by:
I have an issue with the EventHandler for the XmlReaderSettings object being called twice during validation and I'm a little stumpped as to why. The error message being given is the same error...
14
lotus18
by: lotus18 | last post by:
Hello World I have a problem in detecting the conflict schedule (Day and Time). Day 1. M 2. T 3. W 4. TH 5. F
14
lotus18
by: lotus18 | last post by:
Hello all I have these records on my Day Table for my complete database table please click here 1. M 2. T 3. W 4. TH 5. F 6. S
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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...

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.