From edbbe698eb869fe31527ad85981b34ac0cfc4d2a Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 11 Jan 2006 14:58:28 +0000 Subject: [PATCH] Implemented yp2::xml::check_empty that serves as default configure method for filter (in which case no XML config is allowed). --- src/filter.cpp | 4 ++-- src/test_router_flexml.cpp | 6 ++---- src/xmlutil.cpp | 13 ++++++++++++- src/xmlutil.hpp | 5 ++++- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/filter.cpp b/src/filter.cpp index 02c6ff4..ecbec46 100644 --- a/src/filter.cpp +++ b/src/filter.cpp @@ -1,4 +1,4 @@ -/* $Id: filter.cpp,v 1.5 2006-01-11 13:13:49 adam Exp $ +/* $Id: filter.cpp,v 1.6 2006-01-11 14:58:28 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -11,7 +11,7 @@ void yp2::filter::Base::configure(const xmlNode * ptr) { - + yp2::xml::check_empty(ptr); } /* diff --git a/src/test_router_flexml.cpp b/src/test_router_flexml.cpp index 99aa27c..b1b79a1 100644 --- a/src/test_router_flexml.cpp +++ b/src/test_router_flexml.cpp @@ -1,4 +1,4 @@ -/* $Id: test_router_flexml.cpp,v 1.14 2006-01-11 11:51:50 adam Exp $ +/* $Id: test_router_flexml.cpp,v 1.15 2006-01-11 14:58:28 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -45,9 +45,7 @@ BOOST_AUTO_UNIT_TEST( test_router_flexml_1 ) " \n" " my msg\n" " \n" - " \n" - " \n" - " \n" + " \n" " \n" " other\n" " \n" diff --git a/src/xmlutil.cpp b/src/xmlutil.cpp index 600ba5c..d4026b9 100644 --- a/src/xmlutil.cpp +++ b/src/xmlutil.cpp @@ -1,4 +1,4 @@ -/* $Id: xmlutil.cpp,v 1.3 2006-01-11 13:13:49 adam Exp $ +/* $Id: xmlutil.cpp,v 1.4 2006-01-11 14:58:28 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -94,6 +94,17 @@ const xmlNode* yp2::xml::jump_to(const xmlNode* node, return node; } +void yp2::xml::check_empty(const xmlNode *node) +{ + if (node) + { + const xmlNode *n; + for (n = node->children; n; n = n->next) + if (n->type == XML_ELEMENT_NODE) + throw yp2::XMLError("No child elements allowed inside element " + + std::string((const char *) node->name)); + } +} /* * Local variables: diff --git a/src/xmlutil.hpp b/src/xmlutil.hpp index db8636f..fca73fa 100644 --- a/src/xmlutil.hpp +++ b/src/xmlutil.hpp @@ -1,4 +1,4 @@ -/* $Id: xmlutil.hpp,v 1.3 2006-01-11 13:13:49 adam Exp $ +/* $Id: xmlutil.hpp,v 1.4 2006-01-11 14:58:28 adam Exp $ Copyright (c) 2005, Index Data. %LICENSE% @@ -27,6 +27,9 @@ namespace yp2 { const xmlNode* jump_to_next(const xmlNode* node, int node_type); const xmlNode* jump_to_children(const xmlNode* node, int node_type); + + void check_empty(const xmlNode *node); + } class XMLError : public std::runtime_error { public: -- 1.7.10.4