Hello, 

I trying for the first time to validate an XML document with a schema,
but I'm not sure of the results from the parser. I'm currently using
Xerces C++ 2.8.0 DOM Parser. What is the correct syntax to specify a
schema? If the schema and xml file are in the same directory can I just
use the filename of the schema or do I have to specify a full pathname?
If the schema is not in the same directory or location then what is the
correct syntax? 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
Schema 
_XmlDOMParser->setEntityResolver(resolver);

//Turn on the necessary features to allow validation by an external
Schema 
_XmlDOMParser->setValidationScheme(_XmlDOMParser->Val_Always);

//enable schema processing
_XmlDOMParser->setDoSchema(true);

//specify schema to use where scheme syntax is the filename i.e bcme.xsd
_XmlDOMParser->setExternalSchemaLocation((const char* const)schema);
_XmlDOMParser->loadGrammar(schema, Grammar::SchemaGrammarType, true);


//ignore DTD's
_XmlDOMParser->setSkipDTDValidation(false);

//attempt to parse the xml
_XmlDOMParser->parse(xmlDoc2Parse);
==============================================================

Results: Lots of Parser Errors but several of the elments are defined in
the schema. See schema and xml below

The following error occurred during XML Schema or DTD validation

XML Parser Error in file "bcme.xml"

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="BCME_Transform.xsl"?>
Line 3::Column 6        <bcme
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";

Parser Error Message: Unknown element 'bcme'

The following error occurred during XML Schema or DTD validation

XML Parser Error in file "bcme.xml"

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="BCME_Transform.xsl"?>
Line 3::Column 17       <bcme
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";

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

The following error occurred during XML Schema or DTD validation

<?xml-stylesheet type="text/xsl" href="BCME_Transform.xsl"?>
<bcme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
Line 4::Column 32
xsi:noNamespaceSchemaLocation="BCMEdition_v1.1.xds">

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

The following error occurred during XML Schema or DTD validation

<bcme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:noNamespaceSchemaLocation="BCMEdition_v1.1.xds">
Line 5::Column 11       <edition>

Parser Error Message: Unknown element 'edition'

The following error occurred during XML Schema or DTD validation

xsi:noNamespaceSchemaLocation="BCMEdition_v1.1.xds">
<edition>
Line 6::Column 15
<editionid>D633W101-AFA_20080604.0000000000</editionid>

Parser Error Message: Unknown element 'editionid'
==============================================================

XML Document Snippet:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="BCME_Transform.xsl"?>
<bcme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
 xsi:noNamespaceSchemaLocation="BCMEdition_v1.1.xds">
  <edition>
    <editionid>D633W101-AFA_20080604.0000000000</editionid>
    <editionType>Replace</editionType>
    <editionNumber>0000000000</editionNumber>
  </edition>

==============================================================
Schema Snippet

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";>
        
        <xs:element name="bcme">
                <xs:complexType>
                        <xs:sequence>
                                <xs:element ref="edition"/>
                                <xs:element ref="publication"/>
                                <xs:element ref="files"/>
                                <xs:element ref="toc"/>
                        </xs:sequence>
                </xs:complexType>
        </xs:element>
        <xs:element name="edition">
                <xs:complexType>
                        <xs:sequence>
                                <xs:element ref="editionid"/>
                                <xs:element ref="editionType"/>
                                <xs:element ref="editionNumber"/>
                                <xs:element ref="lastEdition"
minOccurs="0"/>
                        </xs:sequence>
                </xs:complexType>
        </xs:element>
==============================================================

DeWayne Dantlzer

Reply via email to