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

Raul Huertas raulh39 at tid.es
Fri Sep 29 05:00:24 EDT 2006


   It works!
   However, I need to make some minor changes to your suggestions:

     First check the "How do I parse an XML instance to a Xerces-C++ DOM
document?" question on the C++/Tree Wiki FAQ[1]; it has the code that
does the XML to DOM parsing. You will need to add the following
includes at the beginning:


#include <xercesc/framework/MemBufInputSource.hpp>
#include <xsd/cxx/xml/string.hxx>

  

also:
#include <xercesc/validators/common/Grammar.hpp>

And the following code after the "Enable/Disable validation" lines:

std::string my_xsd ="<xs:schema ....>...";
  

    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*)([1]"file:///schema.xsd");
    parser->setProperty (
        XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,
        id
    );

 I haven't actually tested this code so let
me know whether it works or not ;-).


   Yes, it works, thank you very much.
   Regards,
   Raul.

References

   1. file://localhost/schema.xsd



More information about the xsd-users mailing list