1 /* $Id: checkxml.cpp,v 1.3 2010/04/24 22:54:57 sarrazip Exp $
2 checkxml.cpp - Checks on the integrity of the XML files
4 verbiste - French conjugation system
5 Copyright (C) 2003-2006 Pierre Sarrazin <http://sarrazip.com/>
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 #error VERBSFRXML expected to be a macro designating the verbs-fr.xml file
31 #include <libxml/xmlmemory.h>
32 #include <libxml/parser.h>
37 static const string testName = "checkxml";
41 xmlDocPtr doc = xmlParseFile(VERBSFRXML);
44 cout << testName << ": could not open " << VERBSFRXML << endl;
48 xmlNodePtr root = xmlDocGetRootElement(doc);
51 cout << testName << ": could not get XML root element" << endl;
54 if (xmlStrcmp(root->name, reinterpret_cast<const xmlChar *>("verbs-fr")) != 0)
56 cout << testName << ": root element is not <verbs-fr>" << endl;
62 set<string> infinitiveSet;
63 for (xmlNodePtr v = root->xmlChildrenNode; v != NULL; v = v->next)
65 //cout << "v->name=\"" << v->name << "\"\n";
66 if (xmlStrcmp(v->name, reinterpret_cast<const xmlChar *>("text")) == 0
67 || xmlStrcmp(v->name, reinterpret_cast<const xmlChar *>("comment")) == 0)
71 xmlNodePtr i = v->xmlChildrenNode;
72 if (i == NULL || i->xmlChildrenNode == NULL)
74 cout << testName << ": missing <i> node at <v> #" << vCounter << endl;
79 string inf = reinterpret_cast<char *>(
80 xmlNodeListGetString(doc, i->xmlChildrenNode, 1));
81 if (infinitiveSet.find(inf) != infinitiveSet.end())
83 cout << testName << ": infinitive \"" << inf
84 << "\" found more than once at <v> #"
90 infinitiveSet.insert(inf);
93 cout << numErrors << " error(s) found.\n";
94 return numErrors == 0 ? EXIT_SUCCESS : EXIT_FAILURE;