473,320 Members | 1,902 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,320 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 3631
"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: 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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
1
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
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.