Dominique,
As far as I know, the only way to do this is to prepend the <!DOCTYPE > declaration before giving the input source to the parser. Something like:
private Reader wrapDoctype(String documentURI, String schemaURI) {
try {
String rootElement = getRootElement(documentURI);
String header = "<?xml version=\"1.0\"?>\n";
header += "<!DOCTYPE " + rootElement + " SYSTEM '" + schemaURI + "'>\n";
StringReader r1 = new StringReader(header);
BufferedReader r2 = new BufferedReader(new FileReader(URLHelper.toFile(documentURI)));
r2.mark(300);
while(true) {
String line = r2.readLine();
if(line.indexOf("<?xml version=\"1.0\"?>")==-1 && line.indexOf("<!DOCTYPE")==-1) {
r2.reset();
break;
}
else {
r2.mark(300);
}
}
return new SequenceReader(r1, r2);
}
catch(Exception e) {
Babble.error(Babble.SYSTEM, e.getMessage());
}
return null;
}
John
> -----Original Message-----
> From: Sauquet Dominique [mailto:[EMAIL PROTECTED]]
> Sent: 20 June 2002 15:52
> To: 'Gopal Sharma'; [EMAIL PROTECTED]
> Subject: RE: problem with DTD
>
>
> Hi Gopal,
>
> the formulation of my problem was not clear enough.
> My question is :
> I have a DTD (I have its URL) and I want to validate XML
> documents(regarding
> this
> particular DTD) THAT DO NOT contain any <!DOCTYPE>.
> How can I do that ?
> A great thanks in advance
>
> Dominique
>
> -----Message d'origine-----
> De : Gopal Sharma [mailto:[EMAIL PROTECTED]]
> Envoy� : mercredi 19 juin 2002 14:11
> � : [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Objet : Re: problem with DTD
>
>
> Hi Sauquet,
>
> You need not to do anything extra, just create a parser
> instance and use
> parse() on that, if you don't require to validate w/ DTD. In case,
> you need to validate it, use
> <!DOCTYPE (roottag) [PUBLIC|SYSTEM] "..location of external
> dtd file" >
> in your instance file and turn the validation (dtd) property ON.
>
> It will be good to see Xerces *Samples* to know more about it.
>
> Thanks
> - Gopal
>
> PS: BTW, It's not clear whether you need separate parse or
> one parse to
> parse all XML instance documents.
>
> Sauquet Dominique wrote:-
> |
> | Hi
> |
> | I want to parse several XML Documents with a DOM Parser to
> get DOM tree
> | representations for my documents.
> | My DTD is in an external file. It is the same for all the documents.
> | The Documents do not contain the DTD !!
> |
> | How can I do ?
> | I am not sure that I have understood this FAQ.
> |
> |
> | How do I more efficiently parse several documents
> sharing a common
> | DTD?
> |
> | DTDs are not currently cached by the parser. The
> common DTD, since
> | it is specified in each XML document, will be re-parsed
> once for each
> | document.
> |
> | However, there are things that you can do now, to make the
> process of
> | reading DTD's more efficient:
> |
> | * keep your DTD and DTD references local
> | * use internal DTD subsets, if possible
> | * load files from server to local client before parsing
> | * Cache document files into a local client cache. You should do an
> | HTTP header request to check whether the document has
> changed, before
> | accessing it over the network.
> | * Do not reference an external DTD or internal DTD subset
> at all. In
> | this case, no DTD will be read.
> | * Use a custom EntityResolver and keep common DTDs in a
> memory buffer.
> |
> |
> |
> | Could you send me the corresponding example or any other example ?
> | Thanks a lot
> | Dominique
> |
> |
> |
> | > Dominique Sauquet
> | > Direction des Moyens Informatiques
> | > Tel : 01 46 84 13 12
> | > <mailto:[EMAIL PROTECTED]>
> | >
> | > Prosodie
> | > 150, rue Galli�ni
> | > 92100 Boulogne
> | > <http://www.prosodie.com/>
> | >
> | >
> | >
> |
> |
> ---------------------------------------------------------------------
> | To unsubscribe, e-mail: [EMAIL PROTECTED]
> | For additional commands, e-mail: [EMAIL PROTECTED]
> |
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
The information transmitted by this e-mail message is intended solely for the use of the person to whom or entity to which it is addressed. The message may contain information that is privileged and confidential. Disclosure, dissemination, distribution, review, retransmission to, other use of or taking any action in reliance upon this information by anyone other than the intended recipient is prohibited. If you are not the intended recipient, please do not disseminate, distribute or copy this communication, by e-mail or otherwise. Instead, please notify us immediately by return e-mail (including the original message with your reply) and then delete and discard all copies of the message.
Although we have taken precautions to minimize the risk of transmitting viruses we nevertheless advise you to carry out your own virus checks on any attachment to this message. We accept no liability for any loss or damage caused by viruses.
