You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Evert Haasdijk <ev...@zukkespijkers.nl> on 2002/01/07 17:40:30 UTC

RE: Telling a parser to validate a document with a DTD non specified in the document

Laurent,

You can set up an empty document that does have the DOCTYPE, create a parser
for that and reuse that parser for new documents.

Here's an example of what that would look like that Alberto Massari sent me
ages ago:

XMLByte* dummyXML="<?xml version=\"1.0\"?> <!DOCTYPE OrderProposalRequest
SYSTEM \"dtd/OrderProposalRequest.dtd\"> <OrderProposalRequest/>";
MemBufInputSource inputSource(dummyXML,strlen(dummyXML),"dummy",false);
SAXParser sp;
sp.setDoValidation(true);
sp.parse(inputSource);

// now, reuse the validator and parse the new doc
FileInputSource inputSource2("somefile.xml");
sp.parse(inputSource2, true);

> -----Original Message-----
> From: Laurent PETIT [mailto:lpetit@sqli.com]
> Sent: Monday, January 07, 2002 18:17 PM
> To: xerces-c-dev@xml.apache.org
> Subject: Telling a parser to validate a document with a DTD non
> specified in the document
>
>
> Hello,
>
> I'm using Xerces C++ on AIX. (Version 1.5.2).
>
> My program receives an XML document.
> I want to validate this document. The problem is that the line
> for the DTD is not present :
> <?xml version="1.0" encoding="iso-8859-1" ?>
> <OrderProposalRequest>
> ...
> </OrderProposalRequest>
>
> The method used in the project is to add a line for the DTD :
> <?xml version="1.0" encoding="iso-8859-1" ?>
> <!DOCTYPE OrderProposalRequest SYSTEM "dtd/OrderProposalRequest.dtd">
> <OrderProposalRequest>
> ...
> </OrderProposalRequest>
>
> This sounds weird to me.
> I think there certainly is a method to tell the parser which DTD
> to use, if none is present in the document ?
>
> I read the documentation of certain classes in xml.apache.org
> apiDoc (SAX2XMLReader, XMLValidator) but I can't guess the way to do it.
>
> Please help.
>
> Thanks in advance,
>
> Laurent PETIT.
>
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Telling a parser to validate a document with a DTD non specified in the document

Posted by Laurent PETIT <lp...@sqli.com>.
Hello Evert,

From: "Evert Haasdijk" <ev...@zukkespijkers.nl>
> Laurent,
> 
> You can set up an empty document that does have the DOCTYPE, create a parser
> for that and reuse that parser for new documents.
> 
> Here's an example of what that would look like that Alberto Massari sent me
> ages ago:
> 
> XMLByte* dummyXML="<?xml version=\"1.0\"?> <!DOCTYPE OrderProposalRequest
> SYSTEM \"dtd/OrderProposalRequest.dtd\"> <OrderProposalRequest/>";
[...]

Well, that's a good solution in that I don't have to modify the real document any longer.
Thanks for it.

Anyway, I'm still not completely satisfied : I have a lot of different incoming documents, and so a lot of different DTDs.

And this solution forces me to do this with each new type of document. The whole set of document types is not known at compile time.

Sorry for the repetition, but I 'll be surprised if there wasn't a way to tell the parser the DTD to use ?
Maybe with the setFeature ?? .... or setProperty ?? 


In any case, thank you for your help,

Laurent PETIT.