~ubuntu-branches/ubuntu/precise/libxml++2.6/precise

« back to all changes in this revision

Viewing changes to examples/dtdvalidation/main.cc

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-03-13 15:46:33 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050313154633-iubyqdtu6y3p8915
Tags: 2.10.0-0ubuntu2
added doxygen to the build-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- C++ -*-
 
2
 
 
3
/* main.cc
 
4
 *
 
5
 * Copyright (C) 2002 The libxml++ development team
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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.
 
20
 */
 
21
 
 
22
 
 
23
#ifdef HAVE_CONFIG_H
 
24
#include <config.h>
 
25
#endif
 
26
 
 
27
#include <libxml++/libxml++.h>
 
28
 
 
29
#include <iostream>
 
30
 
 
31
int main(int argc, char* argv[])
 
32
{
 
33
  Glib::ustring dtdfilepath;
 
34
  if(argc > 1)
 
35
    dtdfilepath = argv[1]; //Allow the user to specify a different dtd file to use.
 
36
  else
 
37
    dtdfilepath = "example.dtd";
 
38
 
 
39
  xmlpp::Document document;
 
40
  xmlpp::Element* nodeRoot = document.create_root_node("incorrect");
 
41
 
 
42
  try
 
43
  {
 
44
    xmlpp::DtdValidator validator( dtdfilepath );
 
45
    try {
 
46
      validator.validate( &document );
 
47
      std::cout << "Validation successfull" << std::endl;
 
48
    }
 
49
    catch( const xmlpp::validity_error& )
 
50
    {
 
51
      std::cout << "Error validating the document" << std::endl;
 
52
    }
 
53
 
 
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");
 
58
 
 
59
    try
 
60
    {
 
61
      xmlpp::DtdValidator validator( dtdfilepath );
 
62
      validator.validate( &document );
 
63
      std::cout << "Validation successfull" << std::endl;
 
64
    }
 
65
    catch( const xmlpp::validity_error& )
 
66
    {
 
67
      std::cout << "Error validating the document" << std::endl;
 
68
    }
 
69
  }
 
70
  catch( const xmlpp::parse_error& )
 
71
  {
 
72
    std::cerr << "Error parsing the dtd" << std::endl;
 
73
  }
 
74
 
 
75
}
 
76