# have all needed files, that a GNU package needs
AUTOMAKE_OPTIONS = foreign 1.4
-SUBDIRS = src configlib test
+SUBDIRS = src configlib xmllib test
# Install the pkg-config file:
pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = libi2ncommon.pc libi2ncommon_config.pc
+pkgconfig_DATA = libi2ncommon.pc libi2ncommon_config.pc libi2ncommon_xml.pc
if AUTOCHECK
all: config.h
AM_CONDITIONAL(AUTOCHECK, test "$enable_autocheck" = yes)
+PKG_CHECK_MODULES(LIBXMLPP, libxml++-2.6 >= 0.2.1)
+AC_SUBST(LIBXMLPP_CFLAGS)
+AC_SUBST(LIBXMLPP_LIBS)
+
PKG_CHECK_MODULES(LIBGETTEXT, libgettext >= 0.0.0)
AC_SUBST(LIBGETTEXT_CFLAGS)
AC_SUBST(LIBGETTEXT_LIBS)
AM_PATH_CPPUNIT(1.8.0)
-AC_OUTPUT(Doxyfile Makefile configlib/Makefile libi2ncommon.pc src/Makefile \
- test/Makefile libi2ncommon_config.pc)
+AC_OUTPUT(Doxyfile Makefile configlib/Makefile xmllib/Makefile libi2ncommon.pc src/Makefile \
+ test/Makefile libi2ncommon_config.pc libi2ncommon_xml.pc)
The config module provides a global configuration system with decentralized
declaration of the config variables.
+%package xml
+Summary: library with a xml module
+Group: Intranator
+Requires: libi2ncommon = %{version}
+
+%description xml
+The xml module provides common xml functions.
%prep
%setup -q
%doc LICENSE
%{prefix}/lib/libi2ncommon_config.so*
+%files xml
+%defattr(-,root,root)
+%doc LICENSE
+%{prefix}/lib/libi2ncommon_xml.so*
--- /dev/null
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libi2ncommon_xml
+Description: library with xml module common in some Intra2net programs
+Requires: libxml++-2.6 libi2ncommon
+Version: @VERSION@
+Libs: -L${libdir} -li2ncommon_xml
+Cflags: -I${includedir}
--- /dev/null
+# set the include path found by configure
+INCLUDES = -I$(top_srcdir)/src $(all_includes) @LIBXMLPP_CFLAGS@ @LIBGETTEXT_CFLAGS@
+METASOURCES = AUTO
+
+lib_LTLIBRARIES = libi2ncommon_xml.la
+
+include_HEADERS = xmlcommon.hpp
+
+# Note: If you specify a:b:c as the version in the next line,
+# the library that is made has version (a-c).c.b. In this
+# example, the version is 2.1.2. (3:2:1)
+
+libi2ncommon_xml_la_LDFLAGS = -version-info @LIBI2NCOMMON_LIB_VERSION@
+
+libi2ncommon_xml_la_LIBADD = @LIBXMLPP_LIBS@
+libi2ncommon_xml_la_SOURCES = xmlcommon.cpp
--- /dev/null
+/***************************************************************************
+ xmlcommon.cpp - Common XML functions
+ -------------------
+ begin : Tue Apr 27 2004
+ copyright : (C) 2004 by Intra2net AG
+ email : info@intra2net.com
+ ***************************************************************************/
+
+#include <xmlcommon.hpp>
+#include <exception.hxx>
+#include <sstream>
+#include <vector>
+
+using namespace xmlpp;
+using namespace std;
+
+namespace I2n {
+
+void xml_validate_dtd(Node *root, const std::string &subsetname, const std::string &dtdname)
+{
+ // Create empty document, set DTD
+ Document doc;
+ doc.set_internal_subset(subsetname, "", dtdname);
+ Element *newRoot = doc.create_root_node(root->get_name(), "", "");
+
+ // Import nodes
+ Node::NodeList list = root->get_children();
+ Node::NodeList::iterator list_end = list.end();
+ for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list_end; ++iter)
+ newRoot->import_node(*iter);
+
+ // Parse XML again to validate it
+ DomParser parser;
+ parser.set_validate();
+ parser.parse_memory(doc.write_to_string_formatted());
+}
+
+std::string xml_get_child_content(xmlpp::Node *base, const std::string &elementname)
+{
+ vector<xmlpp::Node*> nodes;
+
+ // Read in value
+ nodes = base->find(elementname);
+
+ if (nodes.size() != 1)
+ {
+ ostringstream os;
+ os << "xml parse error at line " << base->get_line() << ": element ambiguous or not found: " << elementname;
+ throw EXCEPTION(runtime_error_src,os.str());
+ }
+
+ return xml_get_text_content(nodes[0], elementname);
+}
+
+std::string xml_get_text_content(xmlpp::Node *node, const std::string &elementname)
+{
+ if (node->get_children().size() <= 0)
+ {
+ ostringstream os;
+ os << "xml parse error at line " << node->get_line() << ": element content not found in " << elementname;
+ throw EXCEPTION(runtime_error_src,os.str());
+ }
+
+ xmlpp::Node::NodeList childs = node->get_children();
+ xmlpp::Node::NodeList::iterator text = childs.begin();
+ const xmlpp::ContentNode *nodeText=dynamic_cast<const xmlpp::ContentNode*>(*text);
+
+ if (nodeText)
+ return nodeText->get_content();
+ else
+ {
+ ostringstream os;
+ os << "xml parse error at line " << (*text)->get_line() << ": element " << elementname << " does not contain content";
+ throw EXCEPTION(runtime_error_src,os.str());
+ }
+
+ // not reached
+ return "";
+}
+
+}
--- /dev/null
+/***************************************************************************
+ xmlcommon.hxx - Common XML functions
+ -------------------
+ begin : Tue Apr 27 2004
+ copyright : (C) 2004 by Intra2net AG
+ email : info@intra2net.com
+ ***************************************************************************/
+
+#ifndef __XMLCOMMON
+#define __XMLCOMMON
+
+#include <libxml++/libxml++.h>
+#include <string>
+
+namespace I2n {
+
+void xml_validate_dtd(xmlpp::Node *root, const std::string &subsetname, const std::string &dtdname);
+
+std::string xml_get_child_content(xmlpp::Node *base, const std::string &elementname);
+std::string xml_get_text_content(xmlpp::Node *node, const std::string &elementname);
+
+}
+
+#endif