Hello
 
I'm currently using Xerces C++ 2.7.0 DOM Parser. I want to validate
against an external DTD specified by the caller and not the DTD called
out in the XML document. How is this done with the Xerces API? 

Here's what I've done.

 Code snippet:
 ==========================================================
//perform the necessary DOM Parser init and setup ... omitting all the
gory details

//setup the Entity Resolver to redirect the parser to use the external
DTD 
//to resolve external ENTITY's  and not the DTD called out in the XML
file by the DOCTYPE declaration
//The entire XML file will also be validated against the external DTD as
well
                
        csCtkXmlEntityResolver *resolver = new
csCtkXmlEntityResolver(dtd); <<--- caller specified dtd
        _XmlDOMParser->setEntityResolver(resolver);
                
        //Turn on the necessary features to allow validation by an
external DTD       
        _XmlDOMParser->setValidationScheme(_XmlDOMParser->Val_Always);
        _XmlDOMParser->setDoSchema(false);                      
        _XmlDOMParser->setLoadExternalDTD(true);

        //TODO - How do you load an external DTD???
        //Not sure if this routine does it, but I'll give it a try and
it didn't!!

        _XmlDOMParser->loadGrammar(dtd, Grammar::DTDGrammarType, false);
        _XmlDOMParser->setSkipDTDValidation(false);
        _XmlDOMParser->useCachedGrammarInParse(true);

        ....
        //attempt to parese the XML and get pages of errors             
        }
==============================================================

 Results: Lots of Parser Errors but several of the elments are defined 
 in the DTD

<?xml version="1.0" encoding="UTF-8"?>
line 2::column 6: <bcme
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";

Parser Error Message: Unknown element 'bcme'

<?xml version="1.0" encoding="UTF-8"?>
line 2::column 17: <bcme
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";

Parser Error Message: Attribute 'xmlns:xsi' is not declared for element
'bcme'

<?xml version="1.0" encoding="UTF-8"?>
<bcme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
line 3::column 33:
xsi:noNamespaceSchemaLocation="http://www.boeing.com/commercial/cas_xml/
s1000d/3-0BE1-3/schema/bcme.xsd">

Parser Error Message: Attribute 'xsi:noNamespaceSchemaLocation' is not
declared for element 'bcme'

==============================================================
XML Doc Snippet

<?xml version="1.0" encoding="UTF-8"?>
<bcme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
 
xsi:noNamespaceSchemaLocation="http://www.mycompany.com/cas_xml/schema/a
cme.xsd">
  <edition>
    <editionid>BCMM-21-21-03-81205_20080301.1207260301</editionid>
    <editionType>New</editionType>
    <editionNumber>1207260301</editionNumber>
  </edition>
==================================================================

Best Regards Dewayne

Reply via email to