18 #ifndef VCSN_XML_PARSERS_HXX
19 # define VCSN_XML_PARSERS_HXX
23 # include <xercesc/sax2/XMLReaderFactory.hpp>
35 Parser::get_xsd_path ()
37 static std::string path;
38 static const char xsd[] =
"vaucanson.xsd";
44 const char* base_path = getenv(
"VCSN_DATA_PATH");
47 base_path = VCSN_DATA_PATH;
51 const char* sep = strchr(base_path,
':');
62 path = std::string(base_path, sep - base_path);
64 path = std::string(base_path);
65 path = path +
"/" + xsd;
69 if (std::ifstream(path.c_str()).good())
78 FAIL (std::string(
"Error: cannot open `") + path +
"'.\n"
79 "Please set VCSN_DATA_PATH to the Vaucanson data directory,\n"
80 "containing `" + xsd +
"'.");
84 Parser::Parser (
bool check)
87 using namespace xercesc;
88 parser_ = XMLReaderFactory::createXMLReader();
92 parser_->setFeature(XMLUni::fgSAX2CoreNameSpaces,
true);
93 parser_->setFeature(XMLUni::fgSAX2CoreValidation,
true);
94 parser_->setFeature(XMLUni::fgXercesSchema,
true);
95 parser_->setFeature(XMLUni::fgXercesSchemaFullChecking,
true);
96 parser_->setFeature(XMLUni::fgXercesValidationErrorAsFatal,
true);
97 parser_->setFeature(XMLUni::fgXercesUseCachedGrammarInParse,
true);
98 parser_->setFeature(XMLUni::fgXercesCacheGrammarFromParse,
true);
99 XMLCh* xsd = transcode(VCSN_XMLNS
" " + get_xsd_path());
100 parser_->setProperty(XMLUni::fgXercesSchemaExternalSchemaLocation, xsd);
101 XMLString::release(&xsd);
104 err_handler_ =
new ErrHandler();
105 parser_->setErrorHandler(err_handler_);
117 template <
typename Auto>
118 AutParser<Auto>::AutParser (Auto& a,
bool check)
119 : Parser(check), a_(a)
121 doc_handler_ =
new DocAutHandler<Auto>(parser_, *err_handler_, a_, eq_);
122 parser_->setContentHandler(doc_handler_);
125 template <
typename Auto>
126 AutParser<Auto>::~AutParser ()
131 template <
typename Auto>
135 CxxInputSource is(&in);
142 template <
typename T>
143 RegExpParser<T>::RegExpParser (T& r,
bool check)
144 : Parser(check), r_(r)
146 doc_handler_ =
new DocRegExpHandler<T>(parser_, *err_handler_, r_, eq_);
147 parser_->setContentHandler(doc_handler_);
150 template <
typename T>
151 RegExpParser<T>::~RegExpParser ()
156 template <
typename T>
160 CxxInputSource is(&in);
166 #endif // !VCSN_XML_PARSERS_HXX