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 jeroen clarysse <je...@telenet.be> on 2008/12/27 22:22:16 UTC

MacOS Xcode question

Hi all,

i'm new to this list, so please forgive my ignorance on some matters  
( I did search the archives before posting here though ! )

I'm working on a fairly simple project that involves parsing a lot of  
small XML files for stuff that starts with a certain character, and  
i'm trying to find out if I should use Xerces rather than reinvent the  
wheel.

So I tried compiling Xerces on XCode, and bumped into some problems :-(

I downloaded version 2.8.0 since version 3.0 does not include the  
XCode project files anymore.

compiling went flawless, both on the Xerceslib project and the  
DOMprint & SAXPrint samples. But when running the samples, I get this  
error :

spurious-tuple:Development jeroen$ ./DOMPrint dyld: Library not  
loaded: /Xerces.framework/Versions/A/Xerces
   Referenced from: /Users/jeroen/Downloads/xerces-c-src_2_8_0/ 
Projects/MacOS/Xcode/Samples/DOMPrint/build/Development/./DOMPrint
   Reason: image not found
Trace/BPT trap


I tried copying the framework file (which does exist !) to the / 
Library/Frameworks directory, but that did not help

can anyone give some suggestions on how to get the samples running ? I  
think (hope) that, once I get ONE sample going, the rest should be  
feasible on my own

thanks in advance !

Jeroen 

RE: Validation using a schema

Posted by "Dantzler, DeWayne C" <de...@boeing.com>.
Thanks Alberto

I believe this is now working correctly and my understanding of how to
validate with a schema is better understood. I really appreciated your
assistance.  

DeWayne Dantlzer


-----Original Message-----
From: Alberto Massari [mailto:amassari@datadirect.com] 
Sent: Friday, January 09, 2009 12:21 AM
To: c-users@xerces.apache.org
Subject: Re: Validation using a schema

Dantzler, DeWayne C wrote:
> Ok, I turned on namespace processing using setDoNamespace(true), but 
> the results are not what I expected (see below). I want to use an 
> external schema specified by the caller and not the schema called out 
> in the XML document. How do I do this with Xerces? And what exactly is

> the cause of the below error?
>
> ======================================================================
> ==
> =================
> Error reported by the Parser
>
> <?xml-stylesheet type="text/xsl" href="BCME_Transform.xsl"?> <bcme 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> Line 4::Column 58
> xsi:noNamespaceSchemaLocation="787_BCMEdition_v1.1.xds">
>
> Parser Error Message: The schemaLocation attribute does not contain 
> pairs of values.
>   

You used
  _XmlDOMParser->setExternalSchemaLocation((const char* const)schema);
that requires a string like "uri schema uri2 schema2" (i.e. "pairs of
values") where 'schema' is the location of the schema for the namespace
'uri' and 'schema2' is the location of the schema for the namespace
'uri2'.
In your case the schema is for the empty namespace, so you must use
setExternalNoNamespaceSchemaLocation

Alberto


> ======================================================================
> ==
> ==================
>
> DeWayne Dantlzer
> 206-544-3658
>
>
> -----Original Message-----
> From: Alberto Massari [mailto:amassari@datadirect.com]
> Sent: Thursday, January 08, 2009 11:30 PM
> To: c-users@xerces.apache.org
> Subject: Re: Validation using a schema
>
> You also need to turn on namespace processing using
> setDoNamespaces(true)
>
> Alberto
>
> Dantzler, DeWayne C wrote:
>   
>> 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
>>
>>   
>>     
>
>
>   


Re: XML intro 101 Basics

Posted by David Bertoni <db...@apache.org>.
Dantzler, DeWayne C wrote:
>  Hello
> 
> Can someone explain in XML for Dummies terms the difference between a
> public id and system id? I'm trying to understand how to implement an
> entity resolver and I'm getting tangled on these terms.
You should take a look at the XML recommendation first:

http://www.w3.org/TR/REC-xml/#dt-sysid

In short, a aystem ID is a URI reference to a physical entity.  A public 
ID is a intended to be a symbolic ID which is both unique and canonical.

For example, the a copy of the strict XHTML DTD is hosted by the W3C here:

http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd

and it is identified by the following public ID:

-//W3C//DTD XHTML 1.0 Strict//EN

In the future, please try to limit your postings to Xerces-specific 
questions, rather than general questions about XML.

Dave

XML intro 101 Basics

Posted by "Dantzler, DeWayne C" <de...@boeing.com>.
 Hello

Can someone explain in XML for Dummies terms the difference between a
public id and system id? I'm trying to understand how to implement an
entity resolver and I'm getting tangled on these terms.

Thanks

DeWayne 

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

Correct Usage of LoadGrammar method for Xerces 2.7.0

Posted by "Dantzler, DeWayne C" <de...@boeing.com>.
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: How do you validate against an external DTD

Posted by "Dantzler, DeWayne C" <de...@boeing.com>.
Dave 

Given your explaination on how to use methods loadGrammar and
useCachedCrammarInParse, 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 using the loadGrammar method. I thought
this would force the parser to use the dtd specified in the loadGrammar
method call. 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'	
===================================

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>

====================================
Dantzler, DeWayne C wrote:
> Ok, can someone explain to me what the method 'loadGrammar' actually 
> does and when and why I would use it? Likewise, the same questions for

> the method 'useCachedGrammarInParse'. Hopefully, this will help me to 
> understand how the Parsers validates against a DTD. What is the 
> meaning of 'grammar' in this context and how does the parser generate 
> and use it?
It means "load a grammar from an external resource and return a pointer
to the resulting object."  You can use this object for parsing and
validating instance documents.

You would mostly want to do this if you want to share a grammar between
parsers, or you are interesting in just the grammar object itself.  For
example, it's possible to load a schema grammar, then query the grammar
for interesting information about the types the schema defines.

The flag 'usedCachedGrammarInParse' tells to parser to use any cached
grammar instead of loading the grammar specified by the instance
document.  Consider an instance document with schema location hints. 
Those hints might point to a different schema than the one in the
parser's cache.  If the parser were to always use the cached grammar,
there might be cases where that would not be the right one.  On the
other hand, there might be cases where you would want to force the
parser to use a specific grammar.

"Grammar" in this context means either a DTD or schema, which can be
thought of as grammars for validating particular kinds of XML documents.

> 
> BTW... I read the header files docs on these methods, but could not 
> make sense of what is meant by 'Preparse' schema/dtd grammar. See
below.
> Thanks
"Preparse" simply means the parser reads the grammar and build the
appropriate objects it uses for validating XML instance documents.

The 'toCache' flag instructs the parser to put the grammar object in its
internal cache.

The 'useCachedGrammarInParse' property instructs the parser to always
prefer cached grammars over those specified by the instance document.

Dave

Re: How do you validate against an external DTD

Posted by David Bertoni <db...@apache.org>.
Dantzler, DeWayne C wrote:
> Ok, can someone explain to me what the method 'loadGrammar' actually
> does and when and why I would use it? Likewise, the same questions for
> the method 'useCachedGrammarInParse'. Hopefully, this will help me to
> understand how the Parsers validates against a DTD. What is the meaning
> of 'grammar' in this context and how does the parser generate and use
> it?
It means "load a grammar from an external resource and return a pointer 
to the resulting object."  You can use this object for parsing and 
validating instance documents.

You would mostly want to do this if you want to share a grammar between 
parsers, or you are interesting in just the grammar object itself.  For 
example, it's possible to load a schema grammar, then query the grammar 
for interesting information about the types the schema defines.

The flag 'usedCachedGrammarInParse' tells to parser to use any cached 
grammar instead of loading the grammar specified by the instance 
document.  Consider an instance document with schema location hints. 
Those hints might point to a different schema than the one in the 
parser's cache.  If the parser were to always use the cached grammar, 
there might be cases where that would not be the right one.  On the 
other hand, there might be cases where you would want to force the 
parser to use a specific grammar.

"Grammar" in this context means either a DTD or schema, which can be 
thought of as grammars for validating particular kinds of XML documents.

> 
> BTW... I read the header files docs on these methods, but could not make
> sense of what is meant by 'Preparse' schema/dtd grammar. See below.
> Thanks 
"Preparse" simply means the parser reads the grammar and build the 
appropriate objects it uses for validating XML instance documents.

The 'toCache' flag instructs the parser to put the grammar object in its 
internal cache.

The 'useCachedGrammarInParse' property instructs the parser to always 
prefer cached grammars over those specified by the instance document.

Dave

RE: How do you validate against an external DTD

Posted by "Dantzler, DeWayne C" <de...@boeing.com>.
Ok, can someone explain to me what the method 'loadGrammar' actually
does and when and why I would use it? Likewise, the same questions for
the method 'useCachedGrammarInParse'. Hopefully, this will help me to
understand how the Parsers validates against a DTD. What is the meaning
of 'grammar' in this context and how does the parser generate and use
it?

BTW... I read the header files docs on these methods, but could not make
sense of what is meant by 'Preparse' schema/dtd grammar. See below.
Thanks 

/**
      * Preparse schema grammar (XML Schema, DTD, etc.) via a file path
or URL
      *
      * This method invokes the preparsing process on a schema grammar
XML
      * file specified by the file path parameter. If the 'toCache' flag
      * is enabled, the parser will cache the grammars for re-use. If a
grammar
      * key is found in the pool, no caching of any grammar will take
place.
      *
      * <p><b>"Experimental - subject to change"</b></p>
      *
      * @param systemId A const char pointer to a native string which
contains
      *                 the path to the XML grammar file to be
preparsed.
      * @param grammarType The grammar type (Schema or DTD).
      * @param toCache If <code>true</code>, we cache the preparsed
grammar,
      *                otherwise, no chaching. Default is
<code>false</code>.
      * @return The preparsed schema grammar object (SchemaGrammar or
      *         DTDGrammar). That grammar object is owned by the parser.
      *
      * @exception SAXException Any SAX exception, possibly
      *            wrapping another exception.
      * @exception XMLException An exception from the parser or client
      *            handler code.
      * @exception DOMException A DOM exception as per DOM spec.
      */
    
	Grammar* loadGrammar(const char* const systemId,
                         const short grammarType,
                         const bool toCache = false);

 /** Set the 'Use cached grammar' flag
      *
      * This method allows users to enable or disable the use of cached
      * grammars.  When set to true, the parser will use the cached
grammar,
      * instead of building the grammar from scratch, to validate XML
      * documents.
	
	void useCachedGrammarInParse(const bool newState);

DeWayne Dantlzer
206-544-3658


-----Original Message-----
From: David Bertoni [mailto:dbertoni@apache.org] 
Sent: Friday, January 23, 2009 2:06 PM
To: c-users@xerces.apache.org
Subject: Re: How do you validate against an external DTD

Dantzler, DeWayne C wrote:
> 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?
The easiest way is with an EntityResolver or a DOMLSResourceResolver,
depending on which parsing interface you're using.

> 
> 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);
This value is true by default.

> 
> 	//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);
You've loaded the grammar, but told the parser not to cache it, so it
knows nothing about it.  Please pass 'true' as the last parameter.

> 	_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_xm
> l/
> 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>
> ==================================================================
This document looks like it uses a schema for validation, not a DTD.  In
general, documents that are structured to use XML schema for validation
can be difficult to validate using a DTD.  You might still get some
validation errors, depending on the instance document, and how flexible
the DTD is.

Dave

Re: How do you validate against an external DTD

Posted by David Bertoni <db...@apache.org>.
Dantzler, DeWayne C wrote:
> 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? 
The easiest way is with an EntityResolver or a DOMLSResourceResolver, 
depending on which parsing interface you're using.

> 
> 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);
This value is true by default.

> 
> 	//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);
You've loaded the grammar, but told the parser not to cache it, so it 
knows nothing about it.  Please pass 'true' as the last parameter.

> 	_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>
> ==================================================================
This document looks like it uses a schema for validation, not a DTD.  In 
general, documents that are structured to use XML schema for validation 
can be difficult to validate using a DTD.  You might still get some 
validation errors, depending on the instance document, and how flexible 
the DTD is.

Dave

How do you validate against an external DTD

Posted by "Dantzler, DeWayne C" <de...@boeing.com>.
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

Re: Validation using a schema

Posted by Alberto Massari <am...@datadirect.com>.
Dantzler, DeWayne C wrote:
> Ok, I turned on namespace processing using setDoNamespace(true), but the
> results are not what I expected (see below). I want to use an external
> schema specified by the caller and not the schema called out in the XML
> document. How do I do this with Xerces? And what exactly is the cause of
> the below error?
>
> ========================================================================
> =================
> Error reported by the Parser
>
> <?xml-stylesheet type="text/xsl" href="BCME_Transform.xsl"?>
> <bcme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> Line 4::Column 58
> xsi:noNamespaceSchemaLocation="787_BCMEdition_v1.1.xds">
>
> Parser Error Message: The schemaLocation attribute does not contain
> pairs of values. 
>   

You used
  _XmlDOMParser->setExternalSchemaLocation((const char* const)schema);
that requires a string like "uri schema uri2 schema2" (i.e. "pairs of 
values") where 'schema' is the location of the schema for the namespace 
'uri' and 'schema2' is the location of the schema for the namespace 'uri2'.
In your case the schema is for the empty namespace, so you must use 
setExternalNoNamespaceSchemaLocation

Alberto


> ========================================================================
> ==================
>
> DeWayne Dantlzer
> 206-544-3658
>
>
> -----Original Message-----
> From: Alberto Massari [mailto:amassari@datadirect.com] 
> Sent: Thursday, January 08, 2009 11:30 PM
> To: c-users@xerces.apache.org
> Subject: Re: Validation using a schema
>
> You also need to turn on namespace processing using
> setDoNamespaces(true)
>
> Alberto
>
> Dantzler, DeWayne C wrote:
>   
>> 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
>>
>>   
>>     
>
>
>   


RE: Validation using a schema

Posted by "Dantzler, DeWayne C" <de...@boeing.com>.
Ok, I turned on namespace processing using setDoNamespace(true), but the
results are not what I expected (see below). I want to use an external
schema specified by the caller and not the schema called out in the XML
document. How do I do this with Xerces? And what exactly is the cause of
the below error?

========================================================================
=================
Error reported by the Parser

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

Parser Error Message: The schemaLocation attribute does not contain
pairs of values. 
========================================================================
==================

DeWayne Dantlzer
206-544-3658


-----Original Message-----
From: Alberto Massari [mailto:amassari@datadirect.com] 
Sent: Thursday, January 08, 2009 11:30 PM
To: c-users@xerces.apache.org
Subject: Re: Validation using a schema

You also need to turn on namespace processing using
setDoNamespaces(true)

Alberto

Dantzler, DeWayne C wrote:
> 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
>
>   


Re: Validation using a schema

Posted by Alberto Massari <am...@datadirect.com>.
You also need to turn on namespace processing using setDoNamespaces(true)

Alberto

Dantzler, DeWayne C wrote:
> 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
>
>   


Validation using a schema

Posted by "Dantzler, DeWayne C" <de...@boeing.com>.
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