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

Getting XmlTextReader to skip DOCTYPE in Compact Framework?

Compact Framework SP3 (and I think also SP2 and SP1) XmlTextReader does not
handle !DOCTYPE and (maybe?) rdf elements. How can I get the XmlTextReader to
read these without issuing a NotSupportedException? Or at least to get past
these elements (and nested elements) with an Skip()? I've tried setting
xtr.XmlResolver = null; but it doesn't change the functionality. I'm still
getting the exception.

In a recent MSDN MVP Chat, I was pointed to http://tinyurl.com/5n827 where
it says "Support for parsing DTDs was removed to increase perf and size. It
was considered for .NetCF v2 but was cut again in favor of XmlSchema support."

I'm not asking for XML validation, just a usable way to read the rest of the
XML, while ignoring the DOCTYPE entity. It would be great if I can just
xtr.Skip(), or xtr.MoveToContent() around the DOCTYPE. In my code, if I get
an Exception, I currently try to xtr.Skip() around it, but with SP3, this
creates another NotSupportedException. This may have worked at one time with
SP1 or SP2, I'm not sure. The various flavors of SP1, 2, 3 handle this in
slightly different ways, I think. But I haven't fully characterized this. I
just want this working with SP3 so I can suggest to my users to upgrade, if
necessary.

In desperation, along with xtr.XmlResolver = null; I've also tried
xtr.Namespaces = false; and xtr.Normalization = false;

Obviously to those who are more familiar with how XmlTextReader works, you
may notice that the above properties have nothing to do with my problem.

I have already had to kludge the Encoding because XmlTextReader does not
provide a way to extend the supported text encodings. I hope that I can get
around this DOCTYPE issue easily. I'm considering implementing my own XML
parser. It would be a shame if this becomes necessary. Parsing out the
encoding line is relatively easy (read until the first ">". Parsing the
DOCTYPE is much more difficult because it can include optional nested
elements.

While the XmlTextReader helped me greatly in getting my program going, it is
now in the way of reading some XML documents.
To email me: change to d from delicacy and yahoo from yahoozier.

Nov 12 '05 #1
2 3627
"ec***************@yahoozier.com" <ec***************************@discussions.microso ft.com> wrote in message
news:F5**********************************@microsof t.com...
Compact Framework SP3 (and I think also SP2 and SP1) XmlTextReader does not
handle !DOCTYPE and (maybe?) rdf elements. How can I get the XmlTextReader to
read these without issuing a NotSupportedException? Or at least to get past
these elements (and nested elements) with an Skip()?


XmlTextReader is going to get it's input from a Stream or TextReader
that you can supply. It can only throw a NotSupportedException if
it *sees* your DTD. Therefore, what I would try is to subclass the
appropriate Stream or TextReader you're using as an input source
and write that subclass to "strip out" the DTD. Then your XmlText-
Reader can't see it and shouldn't throw an NSE.
Derek Harmon
Nov 12 '05 #2
Thanks! Your answer makes perfect sense. I *do* think the parsing of DTD in
Compact Framework is broken. It should throw the exception only if I'm trying
to validate. Or it should allow me to .Skip() past the DTD.

XmlTextReader on Compact Framework is apparently for tightly controlled
situations where you can control the writer and reader. It is not for generic
usage on a wide variety of XML input.

I want to be able to read the DTD without validating. And for this,
according to your suggestion, I have to subclass and pre-filter the DTD. I
thought DTDs can be nested, so does that mean I have to generate a recursive
filter. If I'm doing this, why not replace .NET XML with another parser that
can handle ignoring DTDs?

In my opinion, CF.NET XmlTextReader should fail a little more gracefully and
be allowed to fail silently (even if I have to catch the Exception, like I'm
already doing, and use .Skip() to get around the element). It's a little bit
disheartening to get this close with CF.NET XmlTextReader and not be able to
skip/ignore DTDs.

Change to d from delicacy and yahoo from yahoozier to email me (if you want!)

"Derek Harmon" wrote:
"ec***************@yahoozier.com" <ec***************************@discussions.microso ft.com> wrote in message
news:F5**********************************@microsof t.com...
Compact Framework SP3 (and I think also SP2 and SP1) XmlTextReader does not
handle !DOCTYPE and (maybe?) rdf elements. How can I get the XmlTextReader to
read these without issuing a NotSupportedException? Or at least to get past
these elements (and nested elements) with an Skip()?


XmlTextReader is going to get it's input from a Stream or TextReader
that you can supply. It can only throw a NotSupportedException if
it *sees* your DTD. Therefore, what I would try is to subclass the
appropriate Stream or TextReader you're using as an input source
and write that subclass to "strip out" the DTD. Then your XmlText-
Reader can't see it and shouldn't throw an NSE.
Derek Harmon

Nov 12 '05 #3

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

Similar topics

3
by: James | last post by:
I can get the windows version number from System.Environment.OSVersion e.g. "Windows NT 5.1.2600.0" for XP SP2. I was wondering whether this tells you the type of windows it is or if you have to...
4
by: Meir S. | last post by:
I think the following is a bug in XmlTextReader: I need to process large XMLs, that are typically constructed of many small elements nested in the root element. Each inner element represents a...
3
by: keldan | last post by:
I am hoping someone on this list can shed some light on the below issue for me. I am using XmlTextReader to read from an XML file. Unfortunately, an exception is thrown ("Index was outside the...
4
by: Bnaya Eshet | last post by:
I do like XPath, I really do. But I'm working on the compact framework which XPath is not included. So I come to understanding that if XPath do not come to the mountain,
1
by: soupaman | last post by:
Im trying to output some filtered xml using the xmlTextReader I know the code and commenting needs cleaned up and eventually plan to add the values to a dataset. currently what this is doing is...
1
by: SHC | last post by:
Hi all, I did the "Build" on the attached code in my VC++ .NET 2003 - Windows XP Pro PC. On the c:\ screen, I got the following: Microsoft Development Environment An unhandled exception of type...
3
by: Stephen S Kelley | last post by:
I want to do something like: bool bContinueReading=true; XmlTextReader Reader=new XmlTextReader("file.xml"); while(bContinueReading) { try { Reader.Read(); ...
5
by: bob | last post by:
Hi Using 2003 - targeting the compact framework (c#), but would like to do most development using the full.net (manually leaving out stuff not in the compact framework). Q. Trying to find a...
4
by: CodeRazor | last post by:
I am trying to use an XmlTextReader to retrieve data. I need to use an XmlTextReader because it is faster than using an XmlDocument. I have found an inelegant way of retrieving each item's title...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.