[xsd-users] How to validate XML using a in-memory schema

Boris Kolpackov boris at codesynthesis.com
Fri Sep 29 07:47:46 EDT 2006


Hi Raul,

Raul Huertas <raulh39 at tid.es> writes:

>    It works!

Great!


>      const XMLByte*bytes=reinterpret_cast<const XMLByte*>(my_xsd.c_str());
>      MemBufInputSource mis (bytes, my_xsd.size (), "/schema.xsd");
>      Wrapper4InputSource wmis (&mis, false);
>
>      parser->loadGrammar (wmis, Grammar::SchemaGrammarType, true);
>      parser->setFeature (XMLUni::fgXercesUseCachedGrammarInParse, true);
>
>      void* id=(void*)("file:///schema.xsd");
>      parser->setProperty (
>          XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,
>          id
>      );

I don't think this is the right way to set the property because Xerces-C++
expects the string to be XMLCh* (2 bytes per code point) while you are
passing char* (1 byte per code point). I think the right way to do it would
be:


xml::string id ("file:///schema.xsd");
const void* vid (id.c_str ());

parser->setProperty (
  XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,
  const_cast<void*> (vid));

Or, without named temporaries:

parser->setProperty (
  XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,
  const_cast<void*> (
    static_cast<const void*> (
      xml::string ("file:///schema.xsd").c_str ())));


xml::string is a simple string type for Xerces-C++'s XMLCh.

hth,
-boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20060929/6f18b3d0/attachment.pgp


More information about the xsd-users mailing list