5
* Copyright (C) 2002 The libxml++ development team
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Library General Public
9
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* This library 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 GNU
15
* Library General Public License for more details.
17
* You should have received a copy of the GNU Library General Public
18
* License along with this library; if not, write to the Free
19
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
#include <libxml++/libxml++.h>
31
int main(int argc, char* argv[])
33
Glib::ustring dtdfilepath;
35
dtdfilepath = argv[1]; //Allow the user to specify a different dtd file to use.
37
dtdfilepath = "example.dtd";
39
xmlpp::Document document;
40
xmlpp::Element* nodeRoot = document.create_root_node("incorrect");
44
xmlpp::DtdValidator validator( dtdfilepath );
46
validator.validate( &document );
47
std::cout << "Validation successfull" << std::endl;
49
catch( const xmlpp::validity_error& )
51
std::cout << "Error validating the document" << std::endl;
54
xmlpp::Element* nodeRoot = document.create_root_node("example");
55
xmlpp::Element * child = document.get_root_node()->add_child("examplechild");
56
child->set_attribute("id", "an_id");
57
child->add_child("child_of_child");
61
xmlpp::DtdValidator validator( dtdfilepath );
62
validator.validate( &document );
63
std::cout << "Validation successfull" << std::endl;
65
catch( const xmlpp::validity_error& )
67
std::cout << "Error validating the document" << std::endl;
70
catch( const xmlpp::parse_error& )
72
std::cerr << "Error parsing the dtd" << std::endl;