473,761 Members | 9,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to ignore DTD and NOT download it when ValidationType= none?

I'm trying to load and parse an xml file with XmlReader and have it
completely IGNORE the DTD in the xml file. If I set "Validation Type =
ValidationType. None" it STILL downloads the DTD even though it doesn't
validate against it. I get an XmlException when I set "ProhibitDt d =
true" because then no DTD is allowed in the doc. If I manually remove
the DTD reference from the file then it works fine and does not download
the DTD (obviously). How do I leave the DTD in the file but have
XmlReader IGNORE it completely, including not downloading it? It
doesn't seem to be working the way it is supposed to. This is .Net 2.0.
Why would it download it if it's not going to validate against it?

T
Jun 10 '06 #1
3 4864


Thomas S wrote:
I'm trying to load and parse an xml file with XmlReader and have it
completely IGNORE the DTD in the xml file. If I set "Validation Type =
ValidationType. None" it STILL downloads the DTD even though it doesn't
validate against it. I get an XmlException when I set "ProhibitDt d =
true" because then no DTD is allowed in the doc. If I manually remove
the DTD reference from the file then it works fine and does not download
the DTD (obviously). How do I leave the DTD in the file but have
XmlReader IGNORE it completely, including not downloading it? It
doesn't seem to be working the way it is supposed to. This is .Net 2.0.
Why would it download it if it's not going to validate against it?


Well there could still be entity declarations in the DTD and the
entities could be referenced later in the XML document. For instance the
XHTML 1.0 DTDs defined entities like nbsp which are then referenced in a
XHTML document.

Anyway, if you think you don't need to load any external resources then
set XmlResolver to null on the settings of the reader e.g.

XmlReaderSettin gs settings = new XmlReaderSettin gs();
settings.XmlRes olver = null;
settings.Valida tionType = ValidationType. None;
settings.Prohib itDtd = false;
using (XmlReader xmlReader = XmlReader.Creat e(@"file.xml", settings)) {
while (xmlReader.Read ()) {

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 10 '06 #2
Thanks that works great. Is there some way to have it download the DTD
once per app run, but then cache it for subsequent validations within
the same session? As it is it's downloading the same DTD every time I
open a doc with the same DTD url. I would imagine that this would
require subclassing the resolver and adding custom caching code.

T

Martin Honnen wrote:


Thomas S wrote:
I'm trying to load and parse an xml file with XmlReader and have it
completely IGNORE the DTD in the xml file. If I set "Validation Type =
ValidationType. None" it STILL downloads the DTD even though it doesn't
validate against it. I get an XmlException when I set "ProhibitDt d =
true" because then no DTD is allowed in the doc. If I manually remove
the DTD reference from the file then it works fine and does not download
the DTD (obviously). How do I leave the DTD in the file but have
XmlReader IGNORE it completely, including not downloading it? It
doesn't seem to be working the way it is supposed to. This is .Net 2.0.
Why would it download it if it's not going to validate against it?


Well there could still be entity declarations in the DTD and the
entities could be referenced later in the XML document. For instance the
XHTML 1.0 DTDs defined entities like nbsp which are then referenced in a
XHTML document.

Anyway, if you think you don't need to load any external resources then
set XmlResolver to null on the settings of the reader e.g.

XmlReaderSettin gs settings = new XmlReaderSettin gs();
settings.XmlRes olver = null;
settings.Valida tionType = ValidationType. None;
settings.Prohib itDtd = false;
using (XmlReader xmlReader = XmlReader.Creat e(@"file.xml", settings)) {
while (xmlReader.Read ()) {

Jun 10 '06 #3


Thomas S wrote:
Is there some way to have it download the DTD
once per app run, but then cache it for subsequent validations within
the same session? As it is it's downloading the same DTD every time I
open a doc with the same DTD url. I would imagine that this would
require subclassing the resolver and adding custom caching code.


Yes, you can write your own resolver and assign that, it could use a
local copy you install with your application or it could download the
DTD on the first request and then store it locally.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 11 '06 #4

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

Similar topics

17
1676
by: Jan Danielsson | last post by:
Hello all, I recently started using Python, and I must say I like it. Both the language and libraries available for it. Background: I have written an application which I use to keep track of my personal economy. I wrote it in Java because I wanted to learn the language for a course in programming at my university. Now that I have acquired an interrest in Python I was thinking about porting my program to Python.
1
3336
by: ScottF | last post by:
There was a problem with ASP.Net 1.1 creating/generating bad javascript on html pages that I ran into and on the KB page that I had found at the time it said that the problem was fixed in the .Net Framework 1.1 SP 1. So, I ran "NDP1.1sp1-KB867460-X86.exe" thus installing that SP and now I'm getting this very strange "A page can have only one server-side Form tag." error and am wondering if anyone knows how to fix it. The thing is, I...
5
1942
by: Samy | last post by:
Hi There, I have a label in a datagrid which I make it a input type = radio in ItemDataBound so that radio buttons are shown in the datagrid. This is how I have it... ASPX... <asp:Label ID="_selectedRBtn" Runat="server"></asp:Label> ASPX.CS
7
1480
by: Brian Henry | last post by:
I have a list box bound to a data set, of course the datasource,datamember, and valuemember are set, i tell it selecteditem = -1 to make nothing selected, select mode is set to only one item at a time. When the list fills the first item in the listbox has a background rectangle drawn but no focus rectangle (this is NOT a custom drawn listbox, just a standard one).. now i did set -1 as the selected item, but if i tab to the item the focus...
2
5432
by: Michael | last post by:
Hi, I wrote the code to test how CacheItemPriority.NotRemovable works: Cache.Insert("Time", DateTime.Now, new System.Web.Caching.CacheDependency(Server.MapPath("Test.txt")), System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null); When then Test.txt is changed, the cache item "Time" is unavailable,
4
12141
by: J055 | last post by:
Hi I get the error: System.InvalidOperationException: The ReadElementContentAsString method is not supported on node type None. Line 267, position 12. when running the following code: while (reader.Read()) {
18
5002
by: Alan G Isaac | last post by:
>>None >= 0 False True Explanation appreciated. Thanks, Alan Isaac
1
5338
by: Jenny | last post by:
Dear all, I have one select which lists one visible element. I want this select can show scrollbar after I click its down arrow, so that i can use the scrollbar to select the element i want. I test it on windows IE. The scrollbar will be shown when the select has more than 30 elements, otherwise it won't show scrollbar. I don't want the list to be that long. I hope that the scrollbar can be shown when the number of elements is 8.
0
1408
by: samz | last post by:
Hello, Here is a simple PHP recursive file list (with interactive and visual FX) Sam's Files http://acc.jexiste.ch/JPN/RecurciveDIR12.RAR 1. How to ignore/avoid empty folders in this PHP script ? 2. How to sort files by filename (and, if possible, folders on top) ? 3. Is this MAILTO hidden tool still useful against the current Spam robots ? Mysterious Ways - Hide Email Addresses from Spam Harvesters 4. Is my SpamPoison tag useful if I...
0
9376
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9923
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9811
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8813
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.