62 #include <sys/types.h> 83 #include <xercesc/util/XMLString.hpp> 84 using XERCES_CPP_NAMESPACE::XMLString;
107 int fd = open(filenm, O_RDONLY);
109 cerr <<
"unable to open " << docType <<
" file: '" << filenm <<
"': " 110 << strerror(errno) << endl;
115 ssize_t ret =
read(fd, buf, 5);
117 cerr <<
"unable to read " << docType <<
" file: '" << filenm <<
"': " 118 << strerror(errno) << endl;
122 if (strncasecmp(buf,
"<?xml", 5) != 0) {
123 cerr <<
"unable to parse " << docType <<
" file: '" << filenm <<
"': " 124 <<
"not an xml file" << endl;
134 const std::vector<string>& structureFiles,
138 if (structureFiles.empty()) {
return; }
142 for (
uint i = 0; i < structureFiles.size(); ++i) {
143 const string& fnm = structureFiles[i];
144 read_PGM(structure, fnm.c_str(), docty, docargs);
157 if (!filenm || filenm[0] ==
'\0') {
161 string fpath = filenm;
166 if (!fpath.empty()) {
168 SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
170 parser->setFeature(XMLUni::fgSAX2CoreValidation,
true);
171 parser->setFeature(XMLUni::fgXercesDynamic,
true);
172 parser->setFeature(XMLUni::fgXercesValidationErrorAsFatal,
true);
176 parser->setContentHandler(handler);
177 parser->setErrorHandler(handler);
179 parser->parse(fpath.c_str());
181 if (parser->getErrorCount() > 0) {
182 DIAG_Throw(
"ignoring " << fpath <<
" because of previously reported parse errors.");
187 catch (
const SAXException& x) {
188 DIAG_Throw(
"parsing '" << fpath <<
"'" <<
189 XMLString::transcode(x.getMessage()));
192 DIAG_Throw(
"reading '" << fpath <<
"'" << x.
message());
195 DIAG_EMsg(
"While processing '" << fpath <<
"'...");
201 <<
" file '" << filenm <<
"'.");
static const char * ToString(Doc_t docty)
virtual std::string message() const
void read_PGM(Struct::Tree &structure, const char *filenm, PGMDocHandler::Doc_t docty, DocHandlerArgs &docHandlerArgs)
static void xmlSanityCheck(const char *filenm, string &docType)
ssize_t MONITOR_EXT_WRAP_NAME() read(int fd, void *buf, size_t count)
void readStructure(Struct::Tree &structure, const std::vector< string > &structureFiles, PGMDocHandler::Doc_t docty, DocHandlerArgs &docargs)