Re: [xml] schema validation




Your code is ok, here my running result:

# schema x.xml x.xsd
Document validation completed: [x.xml][0]

I'm using 2.6.26.


-----Original Message-----
From: isil light [mailto:isil_light yahoo com] 
Sent: Wednesday, January 24, 2007 1:29 PM
To: Yong Chen (yongche)
Subject: RE: [xml] schema validation

"Yong Chen (yongche)" <chen cisco com> wrote:

      I have been using this api and have not had this problem.
       
      You may want to show your code.
       
      Yong Chen

      #include <stdio.h>
      
      #include <libxml/parser.h>
      #include <libxml/xmlschemas.h>
      
      int main ( int argc, char *argv[] ) {
      
        int ret;
      
        xmlDocPtr doc;
      
        xmlSchemaParserCtxtPtr xsdpctx;
        xmlSchemaPtr xsdctx;
        xmlSchemaValidCtxtPtr xsd;
      
        if ( argc != 3 ) {
      
          fprintf ( stderr,
                    "\nusage: %s doc.xml schema.xsd\n\n",
                    basename ( argv[0] ) );
      
          return ( -1 );
      
        }
      
        if ( ( xsdpctx = xmlSchemaNewParserCtxt ( argv[2] ) ) 
== NULL ) {
      
          fprintf ( stderr,
                    "Unable to create xsd context: [%s]\n",
                    argv[2] );
      
          return ( -1 );
      
        }
      
        if ( ( xsdctx = xmlSchemaParse ( xsdpctx ) ) == NULL ) {
      
          fprintf ( stderr,
                    "Unable to parse xsd: [%s]\n",
                    argv[2] );
      
          xmlSchemaFreeParserCtxt ( xsdpctx );
      
          return ( -1 );
      
        }
      
        if ( ( xsd = xmlSchemaNewValidCtxt ( xsdctx ) ) == NULL ) {
      
          xmlSchemaFree ( xsdctx );
          xmlSchemaFreeParserCtxt ( xsdpctx );
      
          return ( -1 );
      
        }
      
      
        if ( ( doc = xmlParseFile ( argv[1] ) ) == NULL ) {
      
          fprintf ( stderr,
                    "Unable to parse doc: [%s]\n",
                    argv[1] );
      
          xmlSchemaFreeValidCtxt ( xsd );
          xmlSchemaFree ( xsdctx );
          xmlSchemaFreeParserCtxt ( xsdpctx );
      
          return ( -1 );
      
        }
      
        ret = xmlSchemaValidateDoc ( xsd, doc );
      
        fprintf ( stderr,
                  "Document validation completed: [%s][%d]\n",
                  argv[1],
                  ret );
      
        xmlFreeDoc ( doc );
        xmlSchemaFreeValidCtxt ( xsd );
        xmlSchemaFree ( xsdctx );
        xmlSchemaFreeParserCtxt ( xsdpctx );
      
        return ( ret );
      
      }
      

________________________________

Make free worldwide PC-to-PC calls. Try the new Yahoo! Canada 
Messenger with Voice <http://ca.messenger.yahoo.com/> 




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