Hello,
I run on Ubuntu 11.10. I installed libxml++2.6-dev libxml++2.6-doc. I am new to xml++ and to xml / xsd related features. I need to validate an xml file that must be compliant with an xsd file. I must use sax parser to parse the xml file (dom parser will not be suited for my need). In libxml++2.6-doc, I found the following example : /usr/share/doc/libxml++2.6-doc/examples/schemavalidation/example.xml /usr/share/doc/libxml++2.6-doc/examples/schemavalidation/example.xsd /usr/share/doc/libxml++2.6-doc/examples/schemavalidation/main.cc This example enables validation but uses a dom parser. The main steps of this example are : xmlpp::DomParser parser ( xmlFile ); xmlpp::SchemaValidator validator ( xsdFile); validator.validate( parser.get_document () ); I can't figure out how to modify this example to enable validation with xmlpp::SaxParser ? There is no get_document method neither on xmlpp:SaxParser nor on xmlpp:Parser. I tried the following code but it seems not to work either : xmlpp::SchemaValidator validator; validator.parse_file ( xsdFile ); bool validDoc = validator.validate ( xmlFile ); // First validate if ( !validDoc ) { cerr << "XmlChecker ERROR - " << xmlFile << " is not valid" << endl; return 1; } MySaxParser aParser; // MySaxParser derives from xmlpp::SaxParser aParser.set_validate ( true ); aParser.parse_file ( xmlFile ); // Then parse xml What is the correct code ? Am I supposed to add a get_document method on MySaxParser that returns the xmlpp::Document data member entity_resolver_doc_ and then process the same way that works for dom parser ? (As I do not have the code I am not sure this is the right thing to do...) Is it possible to validate an xml file (that refers to an xsd file) using the sax parser provided by libxml++ ? If yes how ? Additional question : is it possible to trigger validation when parsing ? Or I am supposed to validate first ( validator.validate ( ... ) ) and then to parse the xml file ( if validation is OK ) ? FH |