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 "Frank, Ulrich" <Ul...@vector-informatik.de> on 2004/09/14 08:35:09 UTC
Schema validation against a XSD in resource file
Hi,
I'd like to validate my xml files against a xsd file linked to my binary (in a Windows resource).
I use a XercesDOMParser instance to create a DOM of my XML.
Is there a possibility to validate against a string wich contains the xsd resource???
Thanks,
Ulrich
Re: Schema validation against a XSD in resource file
Posted by Simon Kitching <si...@ecnetwork.co.nz>.
On Tue, 2004-09-14 at 18:35, Frank, Ulrich wrote:
> Hi,
>
> I'd like to validate my xml files against a xsd file linked to my
> binary (in a Windows resource).
> I use a XercesDOMParser instance to create a DOM of my XML.
> Is there a possibility to validate against a string wich contains the
> xsd resource???
>
Yes, a schema is located like any other "external entity".
So you just need to create a custom EntityResolver, override the
"resolveEntity" method to return the string you've fetched from the
resource file, and call parser->setEntityResolver(...).
Regards,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
RE: Schema validation against a XSD in resource file
Posted by Matthew Berry <ma...@apt.com>.
Ulrich wrote:
> I'd like to validate my xml files against a xsd file linked to my binary
(in a Windows resource).
> I use a XercesDOMParser instance to create a DOM of my XML.
> Is there a possibility to validate against a string wich contains the xsd
resource???
If you save the import the XSD into your project as an HTML resource, you
could use the following code.
// Load the reporting schema from the resources
const HRSRC hSrcXsd = FindResource(hInstResource,
MAKEINTRESOURCE(IDR_XSD),
RT_HTML);
const HGLOBAL hGblXsd = LoadResource(hInstResource,
hSrcXsd);
const char* const pXsdXml = static_cast<const char*>(
LockResource(hGblXsd) );
You can then add this to a Grammar cache associated with your parser
DOMBuilder* pParser = ...
MemBufInputSource XsdInputSrc(pXsdXml, ....);
pParser->loadGrammar( Wrapper4InputSource(&XsdInputSrc, false),
Grammar::SchemaGrammarType,
true /* Save in Cache */);
pParser->setFeature(XMLUni::fgXercesUseCachedGrammarInParse, true);
Hope this helps
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org