I have a Swing app that stores its data in XML, reading the data back in with Xerces SAX. If my understanding is correct, then those XML data files need to have a DTD defined in the DOCTYPE tag, so I do that like this:
I don't want these data files to be validated by the SAX parser, so I specify as such like this:
However, I've found that even with validation set to false, I still need to provide a DTD for the parser. So in this case (according to my DOCTYPE tag), I need a DTD named "appprefs.dtd" in the same directory as my app's executable. To ensure the existence of that DTD file, before any parsing takes place, I have my app look for that file's existence and if it doesn't exist, writes it out.
The problem with that is that I've discovered that my approach doesn't ensure the DTD's existence. I've had some customers "lose data", and when reviewing their log files, have found that for whatever reasons they sometimes get IOExceptions of the "access denied" variety; they can't write the DTD file to that directory.
So... I'm kind of at a loss at the best way to fix this. Does anyone have a similar scenario that works? Is there a way that I can specify like an in-memory DTD? Or is there same way that I am unaware of that I can just do without providing a DTD altogether?
Thanks in advance. [ April 27, 2005: Message edited by: dave taubler ]
Dave Taubler<br />Specializing in <a href="http://taubler.com/articles/" target="_blank" rel="nofollow">Java and Web Development</a>
William, do you specify a DTD in your DOCTYPE tag, the way I did? Also, what parser do you use (if you're not using Xerces, then maybe yours behaves differently than Xerces?) My parser definitely refuses to parse when the DTD isn't there, but I'm obviously doing something different than you are.
author and deputy
Joined: Jul 13, 2001
I have used Xerces, it worked without dtd. Also the same for Crimson.
Author and all-around good cowpoke
Joined: Mar 22, 2000
I work with XML documents that do not have a DOCTYPE declaration using the Java SDK library XML parsers in Java 1.4 and 1.5. The documents start: <?xml version="1.0" encoding="UTF-8"?> and then have the root element. Bill
Joined: May 15, 2001
Wow. Xerces just chokes when I don't provide a DTD. I removed the
declaration from my XML file, and now a NullPointerException gets thrown from Xerces. I'm trying to keep my app Java 1.3-compatable, but maybe it's time to move to 1.4 and use Java's parsers, and chuck Xerces. It really makes no sense that it would behave that way, though... [ April 28, 2005: Message edited by: dave taubler ]