Bonjour a tous,
je cherche a valider un fichier XML via une grammaire XSD.
Pour ce faire, je me suis tourné vers l'outil xerces de apache.

donc voici mon code actuelle:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
 
#include "StdAfx.h"
#include <iostream>
#include <sys/stat.h>
 
#include "linestyleParser.h"
 
using namespace xercesc;
using namespace std;
 
/**
 * Constructeur du parseur
 * @param strLineStyleFile: String qui contient le path vers le fichier XML
 * @param strXMLGrammarFile: String qui contient le path vers le fichier XSD
 */
linestyleParser::linestyleParser(string& strLineStyleFile ,string& strXMLGrammarFile) 
{
	try {
		XMLPlatformUtils::Initialize();
	}
	catch (...) {
		cout<<"erreur de chargement de la lib xerces"<<endl;
	}
 
	(valideFile(strLineStyleFile))?mStrXMLLinesStyleFile=strLineStyleFile:throw ( std::runtime_error("fichier invalide")); 
	(valideFile(strXMLGrammarFile))?mStrXMLGrammarFile=strXMLGrammarFile:throw ( std::runtime_error("fichier invalide")); 
 
	mFileParser = new XercesDOMParser;
 
}
 
/**
 * Méthode permettant de vérifier si un fichier est accéssible
 * @param file: String qui contient le path vers le fichier a verifier
 * @return true si le fichiers est accessible, false sinon.
 */
bool linestyleParser::valideFile(string& file){
 
	bool valide=true;
 
	struct stat fileStatus;
	int iretStat = stat(file.c_str(), &fileStatus);
	if( iretStat == ENOENT )
		valide=false; //Path file_name does not exist, or path is an empty string.
	else if( iretStat == ENOTDIR )
		valide=false; //A component of the path is not a directory.
	else if( iretStat == EACCES )
		valide=false; //Permission denied.
	else if( iretStat == ENAMETOOLONG )
		valide=false; //File can not be read
 
	return valide;
}
 
/** 
 * Destructeur du parseur
 */
linestyleParser::~linestyleParser(void)
{
	delete mFileParser;
	XMLPlatformUtils::Terminate();
}
 
/************************************************************************/
/*                                                                      */
/************************************************************************/
 
class ParserErrorHandler : public ErrorHandler
{
private:
	void reportParseException(const SAXParseException& ex)
	{
		char* msg = XMLString::transcode(ex.getMessage());
		fprintf(stderr, "at line %llu column %llu, %s\n", 
			ex.getColumnNumber(), ex.getLineNumber(), msg);
		XMLString::release(&msg);
	}
 
public:
	void warning(const SAXParseException& ex)
	{
		reportParseException(ex);
	}
 
	void error(const SAXParseException& ex)
	{
		reportParseException(ex);
	}
 
	void fatalError(const SAXParseException& ex)
	{
		reportParseException(ex);
	}
 
	void resetErrors()
	{
	}
};
 
 
 
 
 
/************************************************************************/
/*                                                                      */
/************************************************************************/
 
 
 
/** 
 * Méthode qui permet de tester la validiter un fichier XML via une grammaire XSD
 * @return true si le fichier est valide, false sinon
 */
bool linestyleParser::validate(void){
	if (mFileParser->loadGrammar(mStrXMLGrammarFile.c_str(), Grammar::SchemaGrammarType) == NULL)
	{
		fprintf(stderr, "couldn't load schema\n");
		return false;
	}
 
	ParserErrorHandler parserErrorHandler;
	mFileParser->setErrorHandler(&parserErrorHandler);
	mFileParser->setValidationScheme(XercesDOMParser::Val_Auto);
	mFileParser->setDoNamespaces(true);
	mFileParser->setDoSchema(true);
	mFileParser->setValidationConstraintFatal(true);
 
	mFileParser->parse(mStrXMLLinesStyleFile.c_str());
	if (mFileParser->getErrorCount() == 0)
		printf("XML file validated against the schema successfully\n");
	else
		printf("XML file doesn't conform to the schema\n");
 
 
	return true;
}
 
/** 
 * Méthode qui permet de récuperer les styles de lignes contenue dans le fichier XML 
 */
void linestyleParser::loadLineStyle(void){
 
 
}
Mon problème est que mon loadGrammar me retourne null....
Pourtant ma variable mStrXMLGrammarFile contient bien le nom du fichier xsd
Ai je fais un oubli ?

Je vous remercie d'avance pour votre aide