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
|
#include <iostream>
#include <fstream>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/sax/HandlerBase.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#if defined(XERCES_NEW_IOSTREAMS)
#include <iostream>
#else
#include <iostream.h>
#endif
using namespace std;
XERCES_CPP_NAMESPACE_USE
int xerces_function () {
try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
cout << "Error during initialization! :\n"
<< message << "\n";
XMLString::release(&message);
return 1;
}
XercesDOMParser* parser = new XercesDOMParser();
parser->setValidationScheme(XercesDOMParser::Val_Always); // optional.
parser->setDoNamespaces(true); // optional
ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
parser->setErrorHandler(errHandler);
char* xmlFile = "test.xml";
try {
parser->parse(xmlFile);
}
catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
cout << "Exception message is: \n"
<< message << "\n";
XMLString::release(&message);
return -1;
}
catch (const DOMException& toCatch) {
char* message = XMLString::transcode(toCatch.msg);
cout << "Exception message is: \n"
<< message << "\n";
XMLString::release(&message);
return -1;
}
catch (...) {
cout << "Unexpected Exception \n" ;
return -1;
}
delete parser;
delete errHandler;
return 0;
}
void ecrire_fichier_xml()
{
ofstream Sortie("test.xml");
Sortie<<"<?xml version=\"1.0\" encoding=\"iso-8859-1\" standalone=\"no\"?>"<<endl;
Sortie<<"<!-- Données XML --> "<<endl;
Sortie<<"<Banque>"<<endl;
Sortie<<"<!-- Nom Client --> "<<endl;
Sortie<<"<client>"<<endl;
Sortie<<"<Nom_client>Martin</Nom_client>"<<endl;
Sortie<<"<!-- debit compte -->"<<endl;
Sortie<<"<debit>100</debit> "<<endl;
Sortie<<"</client>"<<endl;
Sortie<<"</Banque>"<<endl;
Sortie.close();
}
int main(int argc, char *argv[])
{
// utilisation des fichiers
ecrire_fichier_xml();
system("PAUSE");
return EXIT_SUCCESS;
} |
Partager