[libxml++] libxml++ & Schema



Hi :-)

i looked in the API, is in the API and found  the xmlpp::Validator Class Reference

is it posibel to validate XML files with xsd (schema not DTD) ? 

I wrote a Programm based on the testscripts from libxml.. cut & past and tow lines code from me :-)


Greetings 

Frank


#include "Schema_impl.h"
#include <iostream>
#include <libxml/xmlversion.h>
#include <libxml/parser.h>
#include <libxml/xmlmemory.h>
#include <libxml/debugXML.h>
#include <libxml/xmlschemas.h>
#include <libxml/xmlschemastypes.h>


Schema_impl::Schema_impl():schema(NULL)
{
 
}

Schema_impl::~Schema_impl()
{

}

bool Schema_impl::xmlfile(const std::string myxmlfile)
{
  smyxmlfile += myxmlfile;
  const char *pmyxmlfile = myxmlfile.c_str();
  doc = xmlReadFile(pmyxmlfile,NULL,0);
  return (true);
}

bool Schema_impl::xsdfile(const std::string myxsdfile)
{
 const char *pmyxsdfile = myxsdfile.c_str();
 smyxsdfile += myxsdfile;
 xmlSchemaParserCtxtPtr ctxt = xmlSchemaNewParserCtxt(pmyxsdfile);
 schema = xmlSchemaParse(ctxt);
 xmlSchemaFreeParserCtxt(ctxt);
 
 if (schema == NULL)
 {
 xmlSchemaCleanupTypes();
 xmlCleanupParser();
 xmlMemoryDump();
 return (false);
 }
 
 return (true);
}

int Schema_impl::validate() 
{  
   xmlSchemaValidCtxtPtr ctxt = xmlSchemaNewValidCtxt(schema);
   xmlSchemaSetValidErrors(ctxt, (xmlSchemaValidityErrorFunc) fprintf,(xmlSchemaValidityWarningFunc) fprintf,stderr);

   int ret = xmlSchemaValidateDoc(ctxt, doc);

   const char *pmyxmlfile = smyxmlfile.c_str();

   if (ret == 0) {
    printf("%s validates\n", pmyxmlfile );
   } else if (ret > 0) {
    printf("%s fails to validate\n", pmyxmlfile );
   } else {
    printf("%s validation generated an internal error\n", pmyxmlfile );
   }

   xmlSchemaFreeValidCtxt(ctxt);
   xmlFreeDoc(doc);
   xmlSchemaFree(schema);

  return (0);
}
______________________________________________________________
Verschicken Sie romantische, coole und witzige Bilder per SMS!
Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]