471,594 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 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 3562
"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by James | last post: by
4 posts views Thread by Meir S. | last post: by
4 posts views Thread by Bnaya Eshet | last post: by
3 posts views Thread by Stephen S Kelley | last post: by
4 posts views Thread by CodeRazor | last post: by
reply views Thread by Anwar ali | last post: by

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.