Perry Molendijk wrote:
href="file://C:\Program Files\Common Files\Microsoft Shared\Stationery\">
Is there a way to keep the DTD declaration in an xml file when stored in
Xindice. e.g:
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
I have attempted to save a number of DocBook files to Xindice, that all
goes well except for the DTD part. All comments in DTD files are
expanded in the header of the file but the DTD declaration is gone.
Enviroment: JDK 1.3.1, Xindice 1.0, Win2K and I used XMLDB Gui and
Xincon to insert the files.
The DOCTYPE declaration is part of the prolog, not the document
instance, so you shouldn't expect to see it regenerated as
part of the output document. What you are seeing is the addition
of the DTD's comments as part of a document instance following a
parse of its contents. This is (in theory) a feature of the XML
parser, one that can be turned off in the configuration of the
parser by its factory, eg.,
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setIgnoringComments(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Since this is a JAXP API feature it should be independent of
whatever JAXP-compliant XML parser you're using, such as Xerces.
If you want to include the DOCTYPE declaration I believe you can
either see if it's part of the DOM Document by looking for a
DocumentType Node, then serializing its document type name,
public and system IDs. If not, you can build one from scratch
and prepend it.
(If anyone's found a better way, I'm sure we'd all appreciate
hearing about it. I don't use the apache XML serializer myself,
so perhaps there's some methods in it to do this. Dunno. I wrote
my own because I wasn't happy with some of what it did.)
Murray
......................................................................
Murray Altheim <http://kmi.open.ac.uk/people/murray/>
Knowledge Media Institute
The Open University, Milton Keynes, Bucks, MK7 6AA, UK
If you're the first person in a new territory,
you're likely to get shot at.
-- ma