xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sean Kelly" <ke...@mail2a.jpl.nasa.gov>
Subject Re: Building DTD-compliant DOM
Date Mon, 11 Sep 2000 18:26:25 GMT

Try this:

Document toss = new DocumentImpl();
DocumentType docType =
    "-//XYZ//DTD My Special DTD//EN", "http:...");
Document doc = toss.getImplementation().createDocument(null, "rootElem",

If you serialize doc at this point, you'll get:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rootElem PUBLIC "-//XYZ//DTD My Special DTD//EN"

That "null" argument to createDocument is the namespace URI.  Set it if
you're using namespaces.

In my own projects, I hide calls to the *Impl classes in a general XML
service wrapper, so that the XML implementation can change withouth
affecting clients, so that first line goes away and becomes

Document toss = XML.createDocument();

(And in fact, there's an XML.createDTDDoc(...) method, too.)

Now, as for creating the doc nodes so they're compliant with the DTD ...
write careful code!  :-)  Well, seriously, I've never done that part before.
I also recall querying the DTD with XML4J, but I don't know how to do that
with Xerces either.

Good luck.

View raw message