You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by "Dantzler, DeWayne C" <de...@boeing.com> on 2009/02/02 18:32:40 UTC

Correct Usage of LoadGrammar method for Xerces 2.7.0

Hello

I thought that calling the methods loadGrammar and
usedCachedGrammarInParse would force the parser to use the grammar just
loaded instead of loading the grammar specified by the instance
document. I tried the following below and it appears that the parser
attempted to use the DTD specified in the XML file rather than the one I
loaded and cached. What am I missing here? Using Xerces 2.7.0 DOM Impl.

Code snippet
================================
	_XmlDOMParser->setValidationScheme(_XmlDOMParser->Val_Always);
	_XmlDOMParser->setDoSchema(false);
		
	//load grammar and cache it
	_XmlDOMParser->setLoadExternalDTD(true);
	_XmlDOMParser->loadGrammar(dtd, Grammar::DTDGrammarType, true);
	_XmlDOMParser->setSkipDTDValidation(false);
	_XmlDOMParser->useCachedGrammarInParse(true);
	_XmlDOMParser->parse(xmlDoc2Parse);
	
..... The attempt to parse and validate got the error below:

The following error occurred during the XML validation

XML Parser Fatal Error in file
"/net/sinai/home/d/dcd9420/labs/bcmeXmlLab/boldMetaData-PP-777-D633W101-
EAD-51-20070905.xml"

<?xml version="1.0" encoding="UTF-8"?>
Line 2::Column 92	<!DOCTYPE DOCUMENT SYSTEM
"http//web/dtd/ddps_mmm_meta_3.dtd">

Parser Error Message: An exception occurred! Type:NetAccessorException,
Message:Could not read from the socket for URL
'http//web/dtd/ddps_mmm_meta_3.dtd'	

!!! ATTENTION - DON'T WANT TO USE THE DTD SPECIFIED IN THE DOCUMENT
SINCE I CAN'T ACCESS IT
===================================

Snippet of XML file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE DOCUMENT SYSTEM http//web/dtd/ddps_mmm_meta_3.dtd">
<DOCUMENT>
  <APPLICATION VERSION="2.0.3.0507">TECHNICAL DOCUMENTS</APPLICATION>
  <PRODUCT_NUMBER>D633W101-EAD</PRODUCT_NUMBER>


Re: Correct Usage of LoadGrammar method for Xerces 2.7.0

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi DeWayne,

Dantzler, DeWayne C <de...@boeing.com> writes:

> Ok, If I understand your comments correctly, loading a grammar does not
> override the reference specified in an XML instance. So, if the instance
> has an outdated DTD reference and I want to parse against a later
> version, using loadGrammar will cause the Parser to parse against both
> DTD's instead of only against the one loaded via loadGrammar. If this is
> correct, then how can I specify a specific DTD to parse against rather
> than the one specified in the XML instance?

I don't think you can (or want) to do this for the internal subset
(DTD that is embedded into the XML instance itself). For the external
subset, I believe you can do setLoadExternalDTD(false).

Boris

-- 
Boris Kolpackov, Code Synthesis Tools   http://codesynthesis.com/~boris/blog
Open source XML data binding for C++:   http://codesynthesis.com/products/xsd
Mobile/embedded validating XML parsing: http://codesynthesis.com/products/xsde

RE: Correct Usage of LoadGrammar method for Xerces 2.7.0

Posted by "Dantzler, DeWayne C" <de...@boeing.com>.
Ok, If I understand your comments correctly, loading a grammar does not
override the reference specified in an XML instance. So, if the instance
has an outdated DTD reference and I want to parse against a later
version, using loadGrammar will cause the Parser to parse against both
DTD's instead of only against the one loaded via loadGrammar. If this is
correct, then how can I specify a specific DTD to parse against rather
than the one specified in the XML instance?

Thanks 

DeWayne 


-----Original Message-----
From: Boris Kolpackov [mailto:boris@codesynthesis.com] 
Sent: Tuesday, February 03, 2009 12:20 AM
To: c-users@xerces.apache.org
Subject: Re: Correct Usage of LoadGrammar method for Xerces 2.7.0

Hi DeWayne,

Dantzler, DeWayne C <de...@boeing.com> writes:

> I thought that calling the methods loadGrammar and 
> usedCachedGrammarInParse would force the parser to use the grammar 
> just loaded instead of loading the grammar specified by the instance 
> document. I tried the following below and it appears that the parser 
> attempted to use the DTD specified in the XML file rather than the one

> I loaded and cached.

Unlike XML Schema which has a target namespace as a grammar identifier,
for DTD there is no way for the parser to know that the grammar in cache
is the same as the one referenced from XML instance. So, in your case,
the parser will use both grammars. One way to change this might be to do
setLoadExternalDTD(false).

Boris

-- 
Boris Kolpackov, Code Synthesis Tools
http://codesynthesis.com/~boris/blog
Open source XML data binding for C++:
http://codesynthesis.com/products/xsd
Mobile/embedded validating XML parsing:
http://codesynthesis.com/products/xsde

Re: Correct Usage of LoadGrammar method for Xerces 2.7.0

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi DeWayne,

Dantzler, DeWayne C <de...@boeing.com> writes:

> I thought that calling the methods loadGrammar and
> usedCachedGrammarInParse would force the parser to use the grammar just
> loaded instead of loading the grammar specified by the instance
> document. I tried the following below and it appears that the parser
> attempted to use the DTD specified in the XML file rather than the one I
> loaded and cached.

Unlike XML Schema which has a target namespace as a grammar identifier,
for DTD there is no way for the parser to know that the grammar in cache
is the same as the one referenced from XML instance. So, in your case,
the parser will use both grammars. One way to change this might be to
do setLoadExternalDTD(false).

Boris

-- 
Boris Kolpackov, Code Synthesis Tools   http://codesynthesis.com/~boris/blog
Open source XML data binding for C++:   http://codesynthesis.com/products/xsd
Mobile/embedded validating XML parsing: http://codesynthesis.com/products/xsde