├── .github └── workflows │ ├── build_msw_xml_libs.yml │ └── ci.yml ├── .gitignore ├── AUTHORS ├── LICENSE ├── Makefile.am ├── NEWS ├── README.md ├── admin ├── ax_append_compile_flags.m4 ├── ax_append_flag.m4 ├── ax_check_compile_flag.m4 ├── ax_cxx_compile_stdcxx.m4 ├── ax_require_defined.m4 ├── git │ └── ignore_revs └── visibility.m4 ├── configure.ac ├── docs ├── Doxyfile ├── Makefile.am └── manual │ ├── attributes.doxygen │ ├── documents.doxygen │ ├── intro.doxygen │ ├── mainpage.doxygen │ ├── node.doxygen │ ├── parsing.doxygen │ ├── prepare.doxygen │ ├── tips.doxygen │ ├── whatnext.doxygen │ └── xslt.doxygen ├── examples ├── 01-tree_parsing │ ├── Makefile.am │ └── example.cxx ├── 02-event_parsing │ ├── Makefile.am │ └── example.cxx ├── 03-xml_generation │ ├── Makefile.am │ └── example.cxx ├── 04-xslt │ ├── Makefile.am │ ├── example.cxx │ ├── example.xml │ └── example.xsl ├── 05-xpath │ ├── Makefile.am │ ├── example.cxx │ └── example.xml └── Makefile.am ├── include ├── Makefile.am ├── xmlwrapp │ ├── _cbfo.h │ ├── attributes.h │ ├── document.h │ ├── errors.h │ ├── event_parser.h │ ├── export.h │ ├── init.h │ ├── node.h │ ├── nodes_view.h │ ├── relaxng.h │ ├── schema.h │ ├── tree_parser.h │ ├── version.h │ ├── xmlwrapp.h │ └── xpath.h └── xsltwrapp │ ├── init.h │ ├── stylesheet.h │ └── xsltwrapp.h ├── platform └── Win32 │ ├── README │ ├── libxml.props │ ├── master.proj │ ├── test.vcxproj │ ├── test.vcxproj.filters │ ├── xmlwrapp.bkl │ ├── xmlwrapp.sln │ ├── xmlwrapp.vcxproj │ ├── xmlwrapp.vcxproj.filters │ ├── xsltwrapp.vcxproj │ └── xsltwrapp.vcxproj.filters ├── scripts ├── ci │ ├── common.sh │ ├── install-debian.sh │ ├── install-macos.sh │ ├── install-redhat.sh │ ├── install.sh │ └── script.sh └── install_deps.sh ├── src ├── Makefile.am ├── libxml │ ├── ait_impl.cxx │ ├── ait_impl.h │ ├── attributes.cxx │ ├── document.cxx │ ├── dtd_impl.cxx │ ├── dtd_impl.h │ ├── errors.cxx │ ├── errors_impl.h │ ├── event_parser.cxx │ ├── init.cxx │ ├── node.cxx │ ├── node_iterator.cxx │ ├── node_iterator.h │ ├── node_manip.cxx │ ├── node_manip.h │ ├── nodes_view.cxx │ ├── relaxng.cxx │ ├── schema.cxx │ ├── tree_parser.cxx │ ├── utility.cxx │ ├── utility.h │ └── xpath.cxx └── libxslt │ ├── init.cxx │ ├── result.h │ └── stylesheet.cxx ├── tests ├── Makefile.am ├── attributes │ ├── data │ │ ├── 01a.out │ │ ├── 01a.xml │ │ ├── 01b.out │ │ ├── 01b.xml │ │ ├── 01c.out │ │ ├── 01c.xml │ │ ├── 02.out │ │ ├── 02.xml │ │ ├── 03.xml │ │ ├── 04.xml │ │ ├── 04a.out │ │ ├── 04b.out │ │ ├── 04c.out │ │ ├── 04d.out │ │ ├── 06a.xml │ │ ├── 06b.xml │ │ ├── 07a.xml │ │ ├── 07b.xml │ │ ├── 07c.xml │ │ ├── 07d.xml │ │ ├── 08.out │ │ ├── 08.xml │ │ ├── 09.dtd │ │ ├── 09.xml │ │ ├── 10.dtd │ │ └── 10.xml │ └── test_attributes.cxx ├── catch.hpp ├── document │ ├── data │ │ ├── 01.out │ │ ├── 01.xml │ │ ├── 02.out │ │ ├── 03.out │ │ ├── 04.out │ │ ├── 08.out │ │ ├── 09.xml │ │ ├── 10.out │ │ ├── 11.xml │ │ ├── 12.out │ │ ├── 13a.out │ │ ├── 13a.xml │ │ ├── 13b.out │ │ ├── 13b.xml │ │ ├── 14.out │ │ ├── 14.xml │ │ ├── 14inc.xml │ │ ├── 15.out │ │ ├── 17.out │ │ ├── 19.out │ │ └── 21.out │ └── test_document.cxx ├── event │ ├── data │ │ ├── 01.out │ │ └── 01.xml │ └── test_event.cxx ├── node │ ├── data │ │ ├── 01.out │ │ ├── 02.xml │ │ ├── 02_after_move.out │ │ ├── 02a.out │ │ ├── 02c.out │ │ ├── 02g.out │ │ ├── 03.xml │ │ ├── 03a.out │ │ ├── 03b.out │ │ ├── 04.xml │ │ ├── 04a.out │ │ ├── 04b.out │ │ ├── 04c.out │ │ ├── 05.xml │ │ ├── 05a.out │ │ ├── 05b.out │ │ ├── 05c.out │ │ ├── 05d.out │ │ ├── 06a.out │ │ ├── 06a.xml │ │ ├── 06b.out │ │ ├── 06b.xml │ │ ├── 06c.out │ │ ├── 06c.xml │ │ ├── 07a.out │ │ ├── 07a.xml │ │ ├── 07b.out │ │ ├── 07b.xml │ │ ├── 08a.out │ │ ├── 08a.xml │ │ ├── 09.out │ │ ├── 10.out │ │ ├── 11.out │ │ ├── 14.out │ │ ├── copy_ns.out │ │ ├── empty.xml │ │ ├── namespace.out │ │ ├── namespace.xml │ │ └── special_chars.xml │ └── test_node.cxx ├── relaxng │ ├── data │ │ ├── invalid.xml │ │ ├── nonvalid.xml │ │ ├── schema.rnc │ │ ├── schema.rng │ │ └── valid.xml │ └── test_relaxng.cxx ├── schema │ ├── data │ │ ├── invalid.xml │ │ ├── schema.xsd │ │ └── valid.xml │ └── test_schema.cxx ├── test.h ├── test_main.cxx ├── tree │ ├── data │ │ ├── bad.xml │ │ ├── good.xml │ │ └── output │ └── test_tree.cxx ├── xpath │ ├── data │ │ ├── 01.xml │ │ └── 02.xml │ └── test_xpath.cxx └── xslt │ ├── data │ ├── 01a.xsl │ ├── 01b.xsl │ ├── 01c.xsl │ ├── 02a.out │ ├── 02a.xsl │ ├── 03a.out │ ├── 03a.xsl │ ├── input.xml │ └── with_errors.xsl │ └── test_xslt.cxx ├── xmlwrapp-config.in ├── xmlwrapp.pc.in └── xsltwrapp.pc.in /.github/workflows/build_msw_xml_libs.yml: -------------------------------------------------------------------------------- 1 | name: XML MSW binaries 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | build-xml-libs: 8 | name: Build XML binaries 9 | runs-on: ubuntu-latest 10 | container: debian:stable-slim 11 | 12 | strategy: 13 | fail-fast: false 14 | matrix: 15 | include: 16 | - name: 32 Bits 17 | host: i686-w64-mingw32 18 | - name: 64 Bits 19 | host: x86_64-w64-mingw32 20 | 21 | env: 22 | HOST: ${{ matrix.host }} 23 | 24 | steps: 25 | - name: Checkout 26 | uses: actions/checkout@v3 27 | 28 | - name: Install Tools 29 | run: | 30 | apt-get update -qq 31 | arch=`echo $HOST | sed -e 's/-w64-mingw32$//;s/_/-/'` 32 | apt-get install -qq --no-install-recommends g++-mingw-w64-$arch make pkg-config wget 33 | 34 | - name: Build 35 | run: | 36 | # sudo doesn't work and is not necessary inside a container, so don't use it. 37 | SUDO=env ./scripts/install_deps.sh 38 | 39 | - name: Upload 40 | uses: actions/upload-artifact@v3 41 | with: 42 | name: xmllibs-${{ matrix.host }} 43 | path: /usr/local 44 | if-no-files-found: error 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /BUILD-* 2 | docs/html 3 | 4 | *.ncb 5 | *.suo 6 | Debug/ 7 | Release/ 8 | platform/Win32/bin/ 9 | platform/Win32/download/ 10 | platform/Win32/include/ 11 | platform/Win32/lib/ 12 | 13 | Makefile 14 | Makefile.in 15 | configure 16 | aclocal.m4 17 | admin/config.guess 18 | admin/config.sub 19 | admin/install-sh 20 | admin/depcomp 21 | admin/ltmain.sh 22 | admin/missing 23 | autom4te.cache 24 | 25 | /admin/libtool.m4 26 | /admin/ltoptions.m4 27 | /admin/ltsugar.m4 28 | /admin/ltversion.m4 29 | /admin/lt~obsolete.m4 30 | /admin/test-driver 31 | /admin/compile 32 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Current maintainer: 2 | Vaclav Slavik 3 | 4 | Past developers: 5 | Peter J Jones 6 | Eric Beyeler 7 | Tom Browder 8 | 9 | Other contributors: 10 | Sergey Satskiy 11 | Vadim Zeitlin 12 | Tiziano Mueller 13 | Greg Chicares 14 | Daniel Evison 15 | Frank Grimm 16 | Gary Passero 17 | Michael Grundberg 18 | Dmitriy Nikitinskiy 19 | Jonas Weber 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2001-2003 Peter J Jones 2 | Copyright (C) 2009-2014 Vaclav Slavik 3 | Copyright (C) 2014-2020 Vadim Zeitlin 4 | All Rights Reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS = -I admin 2 | 3 | if WITH_DOCS 4 | maybe_docs = docs 5 | endif 6 | 7 | if WITH_EXAMPLES 8 | maybe_examples = examples 9 | endif 10 | 11 | if WITH_TESTS 12 | maybe_tests = tests 13 | endif 14 | 15 | SUBDIRS = include src $(maybe_docs) $(maybe_examples) $(maybe_tests) 16 | 17 | pkgconfigdir=$(libdir)/pkgconfig 18 | 19 | if WITH_XSLT 20 | pkgconfig_DATA = xmlwrapp.pc xsltwrapp.pc 21 | else 22 | pkgconfig_DATA = xmlwrapp.pc 23 | endif 24 | 25 | bin_SCRIPTS = xmlwrapp-config 26 | 27 | EXTRA_DIST = \ 28 | LICENSE \ 29 | $(srcdir)/platform/Win32/README \ 30 | $(srcdir)/platform/Win32/*.proj \ 31 | $(srcdir)/platform/Win32/*.sln \ 32 | $(srcdir)/platform/Win32/*.vcxproj \ 33 | $(srcdir)/platform/Win32/*.vcxproj.filters \ 34 | $(srcdir)/platform/Win32/libxml.props \ 35 | $(srcdir)/platform/Win32/xmlwrapp.bkl 36 | 37 | dist-hook: 38 | cd $(distdir)/platform/Win32 && bkl xmlwrapp.bkl 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 0. Introduction 2 | --------------- 3 | 4 | xmlwrapp is a modern style C++ library for working with XML data, built atop 5 | the venerable libxml2 C library. 6 | 7 | Additional resources, bug reports, latest sources etc. can be found on the 8 | project page at http://vslavik.github.io/xmlwrapp/ 9 | 10 | Packages tarballs can be downloaded from the same location or from 11 | https://github.com/vslavik/xmlwrapp/releases 12 | 13 | If you need help or want to discuss xmlwrapp, feel free to join the discussion 14 | group hosted at http://groups.google.com/group/xmlwrapp or email directly to 15 | xmlwrapp@googlegroups.com. 16 | 17 | 18 | 1. Requirements 19 | --------------- 20 | 21 | In order to build xmlwrapp, you need libxml2 version 2.4.28 or newer. When 22 | building with XSLT support, libxslt 1.1.6 or newer is required. Both libraries 23 | are available from http://xmlsoft.org. 24 | 25 | 26 | 2. Building on Unix 27 | ------------------- 28 | 29 | On Unix, the usual Autotools-based build system is used. Building xmlwrapp is 30 | usually as simple as running the following three commands: 31 | 32 | $ ./configure 33 | $ make 34 | $ make install 35 | 36 | See the output of `./configure --help` for additional settings and options. 37 | 38 | Cross-compiling, notably for Windows, is also supported using the usual 39 | --host option, e.g. --host=x86_64-w64-mingw32. 40 | 41 | Note that if you obtained the library sources from Git, and not from the 42 | release archives, `configure` script won't exist and you will need to run 43 | 44 | $ autoreconf -i 45 | 46 | to create it and other build files. 47 | 48 | 49 | 3. Building on Windows 50 | ---------------------- 51 | 52 | The library can be built either with Microsoft Visual C++ compiler, using the 53 | project files from located in platform/Win32 directory or in the same way as 54 | under Unix, i.e. with configure and make, if you have Cygwin installed (note 55 | that MinGW can be used as a cross-compiler under Cygwin, producing native 56 | libraries without any Cygwin dependencies). In either case, you will need to 57 | either build libxml and libxslt for Windows yourself or download the already 58 | built versions from http://www.zlatkovic.com/libxml.en.html or elsewhere. 59 | 60 | 61 | 4. Using xmlwrapp 62 | ----------------- 63 | 64 | On Unix, you should use pkg-config to get compiler flags for xmlwrapp or 65 | xsltwrapp libraries: 66 | 67 | $ c++ -c `pkg-config --cflags xmlwrapp` ... 68 | $ c++ -o ... `pkg-config --libs xmlwrapp` 69 | 70 | On Windows, you need to link against xmlwrapp libraries and add the include/ 71 | directory to compiler's headers search path. 72 | -------------------------------------------------------------------------------- /admin/ax_append_compile_flags.m4: -------------------------------------------------------------------------------- 1 | # ============================================================================ 2 | # https://www.gnu.org/software/autoconf-archive/ax_append_compile_flags.html 3 | # ============================================================================ 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_APPEND_COMPILE_FLAGS([FLAG1 FLAG2 ...], [FLAGS-VARIABLE], [EXTRA-FLAGS], [INPUT]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # For every FLAG1, FLAG2 it is checked whether the compiler works with the 12 | # flag. If it does, the flag is added FLAGS-VARIABLE 13 | # 14 | # If FLAGS-VARIABLE is not specified, the current language's flags (e.g. 15 | # CFLAGS) is used. During the check the flag is always added to the 16 | # current language's flags. 17 | # 18 | # If EXTRA-FLAGS is defined, it is added to the current language's default 19 | # flags (e.g. CFLAGS) when the check is done. The check is thus made with 20 | # the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to 21 | # force the compiler to issue an error when a bad flag is given. 22 | # 23 | # INPUT gives an alternative input source to AC_COMPILE_IFELSE. 24 | # 25 | # NOTE: This macro depends on the AX_APPEND_FLAG and 26 | # AX_CHECK_COMPILE_FLAG. Please keep this macro in sync with 27 | # AX_APPEND_LINK_FLAGS. 28 | # 29 | # LICENSE 30 | # 31 | # Copyright (c) 2011 Maarten Bosmans 32 | # 33 | # Copying and distribution of this file, with or without modification, are 34 | # permitted in any medium without royalty provided the copyright notice 35 | # and this notice are preserved. This file is offered as-is, without any 36 | # warranty. 37 | 38 | #serial 7 39 | 40 | AC_DEFUN([AX_APPEND_COMPILE_FLAGS], 41 | [AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG]) 42 | AX_REQUIRE_DEFINED([AX_APPEND_FLAG]) 43 | for flag in $1; do 44 | AX_CHECK_COMPILE_FLAG([$flag], [AX_APPEND_FLAG([$flag], [$2])], [], [$3], [$4]) 45 | done 46 | ])dnl AX_APPEND_COMPILE_FLAGS 47 | -------------------------------------------------------------------------------- /admin/ax_append_flag.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_append_flag.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_APPEND_FLAG(FLAG, [FLAGS-VARIABLE]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # FLAG is appended to the FLAGS-VARIABLE shell variable, with a space 12 | # added in between. 13 | # 14 | # If FLAGS-VARIABLE is not specified, the current language's flags (e.g. 15 | # CFLAGS) is used. FLAGS-VARIABLE is not changed if it already contains 16 | # FLAG. If FLAGS-VARIABLE is unset in the shell, it is set to exactly 17 | # FLAG. 18 | # 19 | # NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. 20 | # 21 | # LICENSE 22 | # 23 | # Copyright (c) 2008 Guido U. Draheim 24 | # Copyright (c) 2011 Maarten Bosmans 25 | # 26 | # Copying and distribution of this file, with or without modification, are 27 | # permitted in any medium without royalty provided the copyright notice 28 | # and this notice are preserved. This file is offered as-is, without any 29 | # warranty. 30 | 31 | #serial 8 32 | 33 | AC_DEFUN([AX_APPEND_FLAG], 34 | [dnl 35 | AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_SET_IF 36 | AS_VAR_PUSHDEF([FLAGS], [m4_default($2,_AC_LANG_PREFIX[FLAGS])]) 37 | AS_VAR_SET_IF(FLAGS,[ 38 | AS_CASE([" AS_VAR_GET(FLAGS) "], 39 | [*" $1 "*], [AC_RUN_LOG([: FLAGS already contains $1])], 40 | [ 41 | AS_VAR_APPEND(FLAGS,[" $1"]) 42 | AC_RUN_LOG([: FLAGS="$FLAGS"]) 43 | ]) 44 | ], 45 | [ 46 | AS_VAR_SET(FLAGS,[$1]) 47 | AC_RUN_LOG([: FLAGS="$FLAGS"]) 48 | ]) 49 | AS_VAR_POPDEF([FLAGS])dnl 50 | ])dnl AX_APPEND_FLAG 51 | -------------------------------------------------------------------------------- /admin/ax_check_compile_flag.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check whether the given FLAG works with the current language's compiler 12 | # or gives an error. (Warnings, however, are ignored) 13 | # 14 | # ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on 15 | # success/failure. 16 | # 17 | # If EXTRA-FLAGS is defined, it is added to the current language's default 18 | # flags (e.g. CFLAGS) when the check is done. The check is thus made with 19 | # the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to 20 | # force the compiler to issue an error when a bad flag is given. 21 | # 22 | # INPUT gives an alternative input source to AC_COMPILE_IFELSE. 23 | # 24 | # NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this 25 | # macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. 26 | # 27 | # LICENSE 28 | # 29 | # Copyright (c) 2008 Guido U. Draheim 30 | # Copyright (c) 2011 Maarten Bosmans 31 | # 32 | # Copying and distribution of this file, with or without modification, are 33 | # permitted in any medium without royalty provided the copyright notice 34 | # and this notice are preserved. This file is offered as-is, without any 35 | # warranty. 36 | 37 | #serial 6 38 | 39 | AC_DEFUN([AX_CHECK_COMPILE_FLAG], 40 | [AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF 41 | AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl 42 | AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ 43 | ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS 44 | _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" 45 | AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], 46 | [AS_VAR_SET(CACHEVAR,[yes])], 47 | [AS_VAR_SET(CACHEVAR,[no])]) 48 | _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) 49 | AS_VAR_IF(CACHEVAR,yes, 50 | [m4_default([$2], :)], 51 | [m4_default([$3], :)]) 52 | AS_VAR_POPDEF([CACHEVAR])dnl 53 | ])dnl AX_CHECK_COMPILE_FLAGS 54 | -------------------------------------------------------------------------------- /admin/ax_require_defined.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # https://www.gnu.org/software/autoconf-archive/ax_require_defined.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_REQUIRE_DEFINED(MACRO) 8 | # 9 | # DESCRIPTION 10 | # 11 | # AX_REQUIRE_DEFINED is a simple helper for making sure other macros have 12 | # been defined and thus are available for use. This avoids random issues 13 | # where a macro isn't expanded. Instead the configure script emits a 14 | # non-fatal: 15 | # 16 | # ./configure: line 1673: AX_CFLAGS_WARN_ALL: command not found 17 | # 18 | # It's like AC_REQUIRE except it doesn't expand the required macro. 19 | # 20 | # Here's an example: 21 | # 22 | # AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG]) 23 | # 24 | # LICENSE 25 | # 26 | # Copyright (c) 2014 Mike Frysinger 27 | # 28 | # Copying and distribution of this file, with or without modification, are 29 | # permitted in any medium without royalty provided the copyright notice 30 | # and this notice are preserved. This file is offered as-is, without any 31 | # warranty. 32 | 33 | #serial 2 34 | 35 | AC_DEFUN([AX_REQUIRE_DEFINED], [dnl 36 | m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined; is a m4 file missing?])]) 37 | ])dnl AX_REQUIRE_DEFINED 38 | -------------------------------------------------------------------------------- /admin/git/ignore_revs: -------------------------------------------------------------------------------- 1 | # This file can be used with git blame --ignore-revs-file option or used as 2 | # the value of blame.ignoreRevsFile in git config to ignore the changes done by 3 | # the following "not interesting" commits. 4 | # 5 | # It's supported by Git 2.23 or later and to use it by default for all the 6 | # future git-blame invocations, run the following command: 7 | # 8 | # git config blame.ignoreRevsFile admin/git/ignore_revs 9 | 10 | # Reformatted source code for better readibility., 2009-12-20 11 | 58ab58f90d6d973cdbca3e3e49ffa3e71df6c24f 12 | -------------------------------------------------------------------------------- /admin/visibility.m4: -------------------------------------------------------------------------------- 1 | dnl visibility.m4 serial 1 (gettext-0.15) 2 | dnl Copyright (C) 2005 Free Software Foundation, Inc. 3 | dnl This file is free software; the Free Software Foundation 4 | dnl gives unlimited permission to copy and/or distribute it, 5 | dnl with or without modifications, as long as this notice is preserved. 6 | 7 | dnl From Bruno Haible. 8 | 9 | dnl Modified for use in wxWidgets by Vaclav Slavik: 10 | dnl - don't define HAVE_VISIBILITY (=0) if not supported 11 | dnl - use -fvisibility-inlines-hidden too 12 | dnl - test in C++ mode 13 | 14 | dnl Tests whether the compiler supports the command-line option 15 | dnl -fvisibility=hidden and the function and variable attributes 16 | dnl __attribute__((__visibility__("hidden"))) and 17 | dnl __attribute__((__visibility__("default"))). 18 | dnl Does *not* test for __visibility__("protected") - which has tricky 19 | dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on 20 | dnl MacOS X. 21 | dnl Does *not* test for __visibility__("internal") - which has processor 22 | dnl dependent semantics. 23 | dnl Does *not* test for #pragma GCC visibility push(hidden) - which is 24 | dnl "really only recommended for legacy code". 25 | dnl Set the variable CFLAG_VISIBILITY. 26 | dnl Defines and sets the variable HAVE_VISIBILITY. 27 | 28 | AC_DEFUN([XMLWRAPP_VISIBILITY], 29 | [ 30 | AC_REQUIRE([AC_PROG_CC]) 31 | if test -n "$GCC"; then 32 | CFLAGS_VISIBILITY="-fvisibility=hidden" 33 | CXXFLAGS_VISIBILITY="-fvisibility=hidden -fvisibility-inlines-hidden" 34 | AC_MSG_CHECKING([for symbols visibility support]) 35 | AC_CACHE_VAL(wx_cv_cc_visibility, [ 36 | wx_save_CXXFLAGS="$CXXFLAGS" 37 | CXXFLAGS="$CXXFLAGS $CXXFLAGS_VISIBILITY" 38 | AC_LANG_PUSH(C++) 39 | AC_COMPILE_IFELSE( 40 | [AC_LANG_PROGRAM([], [ 41 | /* we need gcc >= 4.0, older versions with visibility support 42 | didn't have class visibility: */ 43 | #if defined(__GNUC__) && __GNUC__ < 4 44 | error this gcc is too old; 45 | #endif 46 | 47 | /* visibility only makes sense for ELF shared libs: */ 48 | #if !defined(__ELF__) && !defined(__APPLE__) 49 | error this platform has no visibility; 50 | #endif 51 | 52 | extern __attribute__((__visibility__("hidden"))) int hiddenvar; 53 | extern __attribute__((__visibility__("default"))) int exportedvar; 54 | extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void); 55 | extern __attribute__((__visibility__("default"))) int exportedfunc (void); 56 | class __attribute__((__visibility__("default"))) Foo { 57 | Foo() {} 58 | }; 59 | ])], 60 | wx_cv_cc_visibility=yes, 61 | wx_cv_cc_visibility=no) 62 | AC_LANG_POP() 63 | CXXFLAGS="$wx_save_CXXFLAGS"]) 64 | AC_MSG_RESULT([$wx_cv_cc_visibility]) 65 | if test $wx_cv_cc_visibility = yes; then 66 | dnl we do have basic visibility support, now check if we can use it: 67 | dnl 68 | dnl Debian/Ubuntu's gcc 4.1 is affected: 69 | dnl https://bugs.launchpad.net/ubuntu/+source/gcc-4.1/+bug/109262 70 | AC_MSG_CHECKING([for broken libstdc++ visibility]) 71 | AC_CACHE_VAL(wx_cv_cc_broken_libstdcxx_visibility, [ 72 | wx_save_CXXFLAGS="$CXXFLAGS" 73 | wx_save_LDFLAGS="$LDFLAGS" 74 | CXXFLAGS="$CXXFLAGS $CXXFLAGS_VISIBILITY" 75 | LDFLAGS="$LDFLAGS -shared -fPIC" 76 | AC_LANG_PUSH(C++) 77 | AC_LINK_IFELSE( 78 | [AC_LANG_PROGRAM( 79 | [ 80 | #include 81 | ], 82 | [ 83 | std::string s("hello"); 84 | return s.length(); 85 | ])], 86 | wx_cv_cc_broken_libstdcxx_visibility=no, 87 | wx_cv_cc_broken_libstdcxx_visibility=yes) 88 | AC_LANG_POP() 89 | CXXFLAGS="$wx_save_CXXFLAGS" 90 | LDFLAGS="$wx_save_LDFLAGS"]) 91 | AC_MSG_RESULT([$wx_cv_cc_broken_libstdcxx_visibility]) 92 | 93 | if test $wx_cv_cc_broken_libstdcxx_visibility = yes; then 94 | AC_MSG_CHECKING([whether we can work around it]) 95 | AC_CACHE_VAL(wx_cv_cc_visibility_workaround, [ 96 | AC_LANG_PUSH(C++) 97 | AC_LINK_IFELSE( 98 | [AC_LANG_PROGRAM( 99 | [ 100 | #pragma GCC visibility push(default) 101 | #include 102 | #pragma GCC visibility pop 103 | ], 104 | [ 105 | std::string s("hello"); 106 | return s.length(); 107 | ])], 108 | wx_cv_cc_visibility_workaround=no, 109 | wx_cv_cc_visibility_workaround=yes) 110 | AC_LANG_POP() 111 | ]) 112 | AC_MSG_RESULT([$wx_cv_cc_visibility_workaround]) 113 | 114 | if test $wx_cv_cc_visibility_workaround = no; then 115 | dnl we can't use visibility at all then 116 | wx_cv_cc_visibility=no 117 | fi 118 | fi 119 | fi 120 | 121 | if test $wx_cv_cc_visibility = yes; then 122 | AC_DEFINE([HAVE_VISIBILITY]) 123 | if test $wx_cv_cc_broken_libstdcxx_visibility = yes; then 124 | AC_DEFINE([HAVE_BROKEN_LIBSTDCXX_VISIBILITY]) 125 | fi 126 | else 127 | CFLAGS_VISIBILITY="" 128 | CXXFLAGS_VISIBILITY="" 129 | fi 130 | AC_SUBST([CFLAGS_VISIBILITY]) 131 | AC_SUBST([CXXFLAGS_VISIBILITY]) 132 | fi 133 | ]) 134 | -------------------------------------------------------------------------------- /docs/Makefile.am: -------------------------------------------------------------------------------- 1 | doxygen_tagfile = $(abs_builddir)/xmlwrapp.doxytag 2 | 3 | # We use this target just to allow having a rule generating the documentation. 4 | noinst_DATA = $(doxygen_tagfile) 5 | 6 | html_DATA = $(abs_builddir)/html/*.* 7 | 8 | $(doxygen_tagfile): 9 | cd $(srcdir) && DOXYGEN_OUTPUT_DIRECTORY_SLASH="$(abs_builddir)/" doxygen 10 | 11 | EXTRA_DIST = Doxyfile $(srcdir)/manual/*.doxygen 12 | 13 | dist-hook: 14 | cd $(distdir) && doxygen 15 | -------------------------------------------------------------------------------- /docs/manual/attributes.doxygen: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | @page attr Node Attributes 4 | 5 | It is possible for every element type node in an XML node tree to have 6 | attributes. Attributes are nothing more than a collection of name value pairs. 7 | In xmlwrapp, attributes are accessed using the xml::attributes class. This 8 | chapter will show you how to work with objects of this class. 9 | 10 | 11 | @section attr_it Accessing Individual Attributes 12 | 13 | The xml::attributes class is a container of node attributes. It would be pretty 14 | useless if there was no way to access the individual attributes inside of it. 15 | Iterators come to the rescue again. Just like the other xmlwrapp classes, 16 | iterators are used to access the attributes stored inside the xml::attributes 17 | class. 18 | 19 | @subsection attr_it_it Attribute Iterators 20 | 21 | The xml::attributes::iterator and xml::attributes::const_iterator classes point 22 | to a xml::attributes::attr object. This object is what gives you access to the 23 | name and value of a given attribute. In future versions of xmlwrapp, you will 24 | be able to use this class to access the attribute's namespace. 25 | 26 | @code 27 | xml::attributes attrs; 28 | 29 | ... 30 | 31 | xml::attributes::iterator i(attrs.begin()); 32 | 33 | if (i != attrs.end()) 34 | { 35 | std::cout << " name: " << i->get_name() << "\n"; 36 | std::cout << "value: " << i->get_value() << "\n"; 37 | } 38 | @endcode 39 | 40 | @subsection attr_it_begin Begin and End 41 | 42 | If you just wanted to iterate through the attributes, you can use the 43 | xml::attributes::begin() and the xml::attributes::end() member functions. They 44 | both return either a xml::attributes::iterator or 45 | xml::attributes::const_iterator object depending on whether the xml::attributes 46 | object is const or not. 47 | 48 | @subsection attr_it_find Finding Attributes 49 | 50 | When you want to locate an attribute with a given name, you can use the 51 | xml::attributes::find() member function. It will return an iterator that points 52 | to the found attribute or an iterator that is equal to the iterators that the 53 | xml::attributes::end() function returns. 54 | 55 | There is a small difference between the xml::attributes::find() function and 56 | just using the xml::attributes::begin() function to iterate over the 57 | attributes. If the attributes belong to a xml::document object that has been 58 | validated, the xml::attributes::find() function may return an attribute that 59 | was not given in the XML document but contains a default value in the DTD. 60 | 61 | If you are asking the xml::attributes::find() function to find an attribute 62 | that has a default value, but was present in the XML document, the document 63 | version of the attribute is returned. 64 | 65 | 66 | @section attr_add Adding and Replacing Attributes 67 | 68 | Since only one attribute with a given name can exist in a node at any one time, 69 | the same function can be used to both add and replace attributes. When 70 | attempting to add an attribute who has the same name as another attribute in 71 | the container, the old attribute will be removed before the new one is 72 | inserted. 73 | 74 | To add or replace an attribute, you can use the xml::attributes::insert() 75 | member function. It takes the name and value for the attribute to insert. 76 | 77 | 78 | @section attr_remove Removing Attributes 79 | 80 | There are two ways to remove an attribute from a xml::attributes object. Both 81 | involve a call to the xml::attributes::erase() member function. You can remove 82 | an attribute by name, or using an iterator that points to the attribute you 83 | wish to remove. 84 | 85 | */ 86 | -------------------------------------------------------------------------------- /docs/manual/mainpage.doxygen: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | @mainpage 4 | 5 | 6 | @section mainpage_manual Manual 7 | 8 | - @subpage intro 9 | - @subpage intro_xml 10 | - @subpage intro_license 11 | - @subpage intro_audience 12 | - @subpage intro_terms 13 | - @subpage intro_topics 14 | - @subpage prepare 15 | - @subpage prepare_headers 16 | - @subpage prepare_namespace 17 | - @subpage prepare_init 18 | - @subpage parsing 19 | - @subpage parsing_intro 20 | - @subpage parsing_tree 21 | - @subpage parsing_event 22 | - @subpage documents 23 | - @subpage documents_settings 24 | - @subpage documents_subsets 25 | - @subpage documents_valid 26 | - @subpage documents_xinclude 27 | - @subpage documents_children 28 | - @subpage documents_rootnode_get 29 | - @subpage documents_rootnode_set 30 | - @subpage documents_save 31 | - @subpage node 32 | - @subpage node_types 33 | - @subpage node_name 34 | - @subpage node_contents 35 | - @subpage node_children 36 | - @subpage node_add 37 | - @subpage node_remove 38 | - @subpage node_attr 39 | - @subpage attr 40 | - @subpage attr_it 41 | - @subpage attr_add 42 | - @subpage attr_remove 43 | - @subpage xslt 44 | - @subpage xslt_init 45 | - @subpage xslt_stylesheet 46 | - @subpage xslt_apply_ne 47 | - @subpage xslt_apply_we 48 | - @subpage tips 49 | - @subpage tips_lifetime 50 | - @subpage tips_debugging 51 | - @subpage whatnext 52 | 53 | 54 | @section mainpage_refdocs Reference documentation 55 | 56 | Reference documentation for all classes. 57 | 58 | */ 59 | -------------------------------------------------------------------------------- /docs/manual/prepare.doxygen: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | @page prepare Preparing To Use xmlwrapp 4 | 5 | Before you use xmlwrapp there are a few things you will need to 6 | know. This chapter will give you all the background you need to 7 | understand the rest of this book. 8 | 9 | @section prepare_headers Header Files 10 | 11 | When you install xmlwrapp, a set of header files will be installed in the 12 | include directory of your choosing. If you don't pick a location for these file 13 | to go, they will be installed in /usr/local/include by default. All of the 14 | xmlwrapp header files will be placed into a @c xmlwrapp subdirectory. 15 | 16 | If you are using the @c pkg-config script, you don't have to worry about where 17 | the xmlwrapp header files were installed. @c "pkg-config xmlwrapp" will add the 18 | appropriate directory to the compiler's search path. 19 | 20 | When using the xmlwrapp header files, you can either include each 21 | file you need or use the master include file to include all 22 | xmlwrapp header files. The choice is yours and mainly depends on 23 | your style and the project you are working on. 24 | 25 | @subsection using_win32_dll Using DLLs under Microsoft Windows systems 26 | 27 | If xmlwrapp was built as a DLL, you must predefine @c XMLWRAPP_USE_DLL before 28 | including any of the library headers, e.g. typically in the project build 29 | options. Similarly, @c XSLTWRAPP_USE_DLL must be defined when using xsltwrapp 30 | as a DLL. 31 | 32 | Note that this it is not necessary to do this when using GNU toolset, as GNU 33 | linker can automatically import symbols from the DLLs as needed. However this 34 | is required when using other toolsets, such as Microsoft C++ one, and may be 35 | slightly more efficient than relying on auto-linking even with GNU linker. 36 | 37 | @subsection prepare_headers_example1 Include xmlwrapp Header Files 38 | 39 | @code 40 | #include 41 | #include 42 | @endcode 43 | 44 | @subsection prepare_headers_example2 Include All xmlwrapp Header Files 45 | 46 | @code 47 | #include 48 | @endcode 49 | 50 | @section prepare_namespace The xmlwrapp Namespace 51 | 52 | To prevent pollution of the global namespace, xmlwrapp places all classes and 53 | functions in the xml namespace. For clarity, this document will always use the 54 | xml namespace prefix when showing examples. 55 | 56 | It is your choice if you want to use the xml namespace in your code, or use 57 | one of the many forms of the "using namespace" statement. 58 | 59 | 60 | @section prepare_init Initializing the XML Parser 61 | 62 | Starting with xmlwrapp version 0.6.0, you don't have to explicitly initialize 63 | the library, it is automatically initialized at startup time, in a thread-safe 64 | way. 65 | 66 | You may want to configure the libxml2 parser to behave differently from 67 | its default behavior. The xml::init class exists for this purpose and provides 68 | several static methods for configuring various aspects of libxml2. If you 69 | decide to tweak the defaults, it is generally good idea to do it before 70 | first use of xmlwrapp, as setting the defaults is @em not thread-safe and 71 | has global effect. 72 | 73 | @code 74 | int main() { 75 | xml::init::remove_whitespace(true); 76 | ... 77 | return 0; 78 | } 79 | @endcode 80 | 81 | 82 | */ 83 | -------------------------------------------------------------------------------- /docs/manual/tips.doxygen: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | @page tips Tips, Tricks and Warnings 4 | 5 | @section tips_lifetime Iterators and Object Lifetimes 6 | 7 | Because of the way xmlwrapp is implemented, you must be careful 8 | with pointers and references that you take from xmlwrapp 9 | iterators. The pointers and references will only be valid as long 10 | as the iterator is valid. 11 | 12 | From the xmlwrapp-users mailing list: 13 | 14 |
15 | From: Peter Jones 
16 | Subject: Re: [xmlwrapp-users] Potential bug in xml::node::iterator dereferencing?
17 | Date: Fri, 21 Mar 2003 07:47:05 -0800
18 | 
19 | It does seem strange on the surface that xml::node::iterator has an
20 | xml::node as a member variable. However, xml::node::iterator is really a
21 | shell class that uses the pimpl idiom to contain another class, and that
22 | class is what holds the xml::node.
23 | 
24 | I would much prefer to emulate the standard containers in this respect,
25 | and I would love to hear any suggestions on how this might be done.
26 | 
27 | Let me explain the problem as I see it, and maybe you and others can
28 | point me in the right direction.
29 | 
30 | xml::node is somewhat like a std::list. From the outside it looks as if
31 | xml::node is a container for other xml::node objects, however, this is
32 | not true. The objects that xml::node contains are really pointers to
33 | libxml2 data structures.
34 | 
35 | I decided early on that, unlike other libxml2 C++ libraries, xmlwrapp
36 | should not try to duplicate the XML tree using C++ containers, but
37 | instead emulate that container interface and adapt it to the libxml2
38 | function calls.
39 | 
40 | It is quite easy for the standard containers to return a valid
41 | pointer/reference to their contained objects since those objects are
42 | already in memory, and will be around until the container goes away or
43 | an operation is preformed on that container that would invalidate those
44 | pointers/references.
45 | 
46 | But, xml::node is keeping pointers to xmlNode structs, not xml::node
47 | classes. This means that the xml::node::iterators could return pointers
48 | to xmlNode structs that out live the iterator, but that is not what
49 | users would expect.
50 | 
51 | Currently, the xml::node::iterator will use its xml::node member
52 | variable as a way to pretend that xml::node objects are containers for
53 | other xml::node objects. This is why the lifetime of the xml::node is
54 | limited to the lifetime of the xml::node::iterator.
55 | 
56 | 57 | @section tips_debugging Debugging 58 | 59 | Any xml::node object can be easily examined by dumping it to a string using its 60 | xml::node::node_to_string() method or by outputting it into any standard 61 | stream: 62 | @code 63 | xml::node n = ...; 64 | std::cout << "Contents of the node: " << n; 65 | @endcode 66 | 67 | Notice that the node_to_string() function can even be called from a debugger to 68 | see the contents of the node during a debugging session. 69 | 70 | */ 71 | -------------------------------------------------------------------------------- /docs/manual/whatnext.doxygen: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | @page whatnext Where To Go From Here 4 | 5 | Like most programming tasks, the best place to start is to just dive 6 | in. The most obvious place to look is the xmlwrapp header files. They 7 | are clean and well documented. When any document does not agree with 8 | the header file, the header file will always win. 9 | 10 | The header files are documented using the 11 | Doxygen 12 | syntax. The comments are then used to build the API reference 13 | manual. 14 | 15 | 16 | @section whatnext_help Getting Help 17 | 18 | Additional resources, bug reports, latest sources etc. can be found on the 19 | project page. 20 | 21 | If you need help or want to discuss xmlwrapp, feel free to join the 22 | xmlwrapp mailing list. 23 | 24 | */ 25 | -------------------------------------------------------------------------------- /docs/manual/xslt.doxygen: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | @page xslt Using the XSLT Support 4 | 5 | Starting with version 0.4.0, xmlwrapp supports XSLT using the 6 | libxslt XSLT library. If @c configure 7 | detects that you have libxslt installed, it will enable the creation of a 8 | library called @c xsltwrapp. 9 | 10 | The two main classes that you should care about are 11 | xslt::init and 12 | xslt::stylesheet. There is also a general 13 | header file that will bring in all of xsltwrapp and xmlwrapp called 14 | xsltwrapp/xsltwrapp.h. 15 | 16 | 17 | @section xslt_init Configuring xsltwrapp 18 | 19 | Similarly to xml::init, the xslt::init class can be used to configure 20 | runtime behavior of libxslt. 21 | 22 | @see @ref prepare_init 23 | 24 | 25 | @section xslt_stylesheet The xslt::stylesheet Class 26 | 27 | The xslt::stylesheet class can be used to parse an XSLT stylesheet and apply it 28 | to another XML document to produce a results document. You can have the 29 | xslt::stylesheet class parse a XSLT file, or you can give it an xml::document 30 | object that contains the stylesheet tree. 31 | 32 | Once you have created an xslt::stylesheet object, you can apply the loaded 33 | stylesheet to any xml::document object. The resulting document is also returned 34 | in an xml::document object. 35 | 36 | 37 | @section xslt_apply_ne Applying the Stylesheet without Exceptions 38 | 39 | If you don't want xsltwrapp to throw an exception for transformation errors, 40 | you can use one of the two xslt::stylesheet::apply() member functions that take 41 | a reference to an xml::document object where the results should be placed. 42 | These functions return a @c bool to indicate if the transformation was 43 | successful or not. These functions have the following prototypes: 44 | - bool xslt::stylesheet::apply(const xml::document& doc, xml::document& result) 45 | - bool xslt::stylesheet::apply(const xml::document& doc, xml::document& result, const param_type& with_params) 46 | 47 | 48 | @section xslt_apply_we Applying the Stylesheet with the Possibility of Exceptions 49 | 50 | You can have xsltwrapp throw an exception (std::runtime_error) if the 51 | transformation fails. This is done using the two versions of the 52 | xslt::stylesheet::apply() member function that return the resulting document. 53 | They return a reference to the results document, when the transformation was 54 | successful. These functions have the following prototypes: 55 | 56 | - xml::document& xslt::stylesheet::apply(const xml::document& doc); 57 | - xml::document& xslt::stylesheet::apply(const xml::document& doc, const param_type& with_params); 58 | 59 | */ 60 | -------------------------------------------------------------------------------- /examples/01-tree_parsing/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | noinst_PROGRAMS = example 3 | 4 | example_SOURCES = example.cxx 5 | example_CPPFLAGS = -I$(top_srcdir)/include 6 | example_LDADD = ../../src/libxmlwrapp.la 7 | -------------------------------------------------------------------------------- /examples/01-tree_parsing/example.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org) 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | /* 34 | * This file demonstrates how to use the xml::tree_parser class to parse XML 35 | * data and create a tree of xml::node objects. It also shows how you can 36 | * walk the tree using xml::node iterators. 37 | */ 38 | 39 | // xmlwrapp include 40 | #include 41 | 42 | // standard includes 43 | #include 44 | #include 45 | 46 | int main (int argc, char *argv[]) { 47 | if (argc != 2) { 48 | std::cerr << argv[0] << ": you must give one and only one XML file name\n"; 49 | return 1; 50 | } 51 | 52 | try { 53 | 54 | xml::tree_parser parser(argv[1]); 55 | 56 | xml::node &root = parser.get_document().get_root_node(); 57 | std::cout << "root node is '" << root.get_name() << "'\n"; 58 | 59 | for (auto const& child : root) { 60 | if (child.is_text()) continue; 61 | std::cout << "child node '" << child.get_name() << "'\n"; 62 | } 63 | 64 | } catch (std::exception &e) { 65 | std::cerr << argv[0] << ": " << e.what() << "\n"; 66 | return 1; 67 | } 68 | 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /examples/02-event_parsing/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | noinst_PROGRAMS = example 3 | 4 | example_SOURCES = example.cxx 5 | example_CPPFLAGS = -I$(top_srcdir)/include 6 | example_LDADD = ../../src/libxmlwrapp.la 7 | -------------------------------------------------------------------------------- /examples/02-event_parsing/example.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org) 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | /* 34 | * The following code demonstrates the usage of the xml::event_parser class. 35 | * This class must be derived from and the new subclass must implement the 36 | * pure virtual member functions from xml::event_parser. These member 37 | * functions are called when parsing events occur. 38 | */ 39 | 40 | // xmlwrapp include 41 | #include 42 | 43 | // standard includes 44 | #include 45 | #include 46 | 47 | /* 48 | * Here we create a class that will receive the parsing events. 49 | */ 50 | class myparser : public xml::event_parser { 51 | public: 52 | myparser () 53 | { std::cout << "myparser constructor\n"; } 54 | 55 | ~myparser () override 56 | { std::cout << "myparser destructor\n"; } 57 | private: 58 | bool start_element (const std::string &name, const attrs_type&) override 59 | { std::cout << "begin tag '" << name << "'\n"; return true; } 60 | 61 | bool end_element (const std::string &name) override 62 | { std::cout << "end tag '" << name << "'\n"; return true; } 63 | 64 | bool text (const std::string&) override 65 | { return true; } 66 | }; 67 | 68 | /* 69 | * And here is good ol' main. 70 | */ 71 | int main (int argc, char *argv[]) { 72 | if (argc != 2) { 73 | std::cerr << argv[0] << ": you must give one and only one XML file name\n"; 74 | return 1; 75 | } 76 | 77 | myparser parser; 78 | 79 | if (!parser.parse_file(argv[1])) { 80 | std::cerr << argv[0] << ": error parsing XML file\n"; 81 | return 1; 82 | } 83 | 84 | return 0; 85 | } 86 | -------------------------------------------------------------------------------- /examples/03-xml_generation/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | noinst_PROGRAMS = example 3 | 4 | example_SOURCES = example.cxx 5 | example_CPPFLAGS = -I$(top_srcdir)/include 6 | example_LDADD = ../../src/libxmlwrapp.la 7 | -------------------------------------------------------------------------------- /examples/03-xml_generation/example.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org) 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | /* 34 | * The following code demonstrates how to use the xml::node class to build 35 | * an XML tree and then convert it to XML text. 36 | * 37 | * Here is what we want to create: 38 | * 39 | * 40 | * 41 | * pjones@pmade.org 42 | * 43 | * 555-1212 44 | * 45 | * 46 | */ 47 | 48 | // xmlwrapp include 49 | #include 50 | 51 | // standard includes 52 | #include 53 | #include 54 | 55 | int main () { 56 | // create a new XML document and set the root node 57 | xml::document xmldoc(xml::node("abook")); 58 | xml::node &root = xmldoc.get_root_node(); 59 | 60 | // add a child to the root node, 61 | xml::node::iterator it = root.insert(root.begin(), xml::node("person")); 62 | 63 | /* 64 | * set the attributes for this new element using the 65 | * xml::attributes object returned from xml::node::get_attributes 66 | */ 67 | it->get_attributes().insert("id", "01"); 68 | it->get_attributes().insert("name", "Peter Jones"); 69 | 70 | // add a node and set the content for that new node 71 | it->push_back(xml::node("email", "pjones@pmade.org")); 72 | 73 | // add an XML comment 74 | it->push_back(xml::node(xml::node::comment(" Fake Phone Number "))); 75 | 76 | // build a node one member function at a time 77 | it = it->insert(xml::node("phone")); 78 | it->get_attributes().insert("type", "home"); 79 | it->set_content("555-1212"); 80 | 81 | // set some document settings 82 | xmldoc.set_is_standalone(true); 83 | xmldoc.set_encoding("ISO-8859-1"); 84 | 85 | // convert the document to XML 86 | std::cout << xmldoc; 87 | return 0; 88 | } 89 | -------------------------------------------------------------------------------- /examples/04-xslt/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | if WITH_XSLT 3 | 4 | noinst_PROGRAMS = example 5 | 6 | example_SOURCES = example.cxx 7 | example_CPPFLAGS = -I$(top_srcdir)/include 8 | example_LDADD = ../../src/libxsltwrapp.la ../../src/libxmlwrapp.la 9 | 10 | endif 11 | 12 | EXTRA_DIST = example.xml example.xsl 13 | -------------------------------------------------------------------------------- /examples/04-xslt/example.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org) 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | /* 34 | * The following code demonstrates how to use the xsltwrapp code to trasform 35 | * an XML document into something else using XSLT. 36 | */ 37 | 38 | // xsltwrapp include 39 | #include 40 | 41 | // standard includes 42 | #include 43 | #include 44 | 45 | int main () { 46 | try { 47 | // parse the input XML document 48 | xml::tree_parser parser("example.xml"); 49 | xml::document &doc = parser.get_document(); 50 | 51 | // parse the stylesheet 52 | xslt::stylesheet style("example.xsl"); 53 | 54 | // transform the XML document using the stylesheet 55 | xml::document &result = style.apply(doc); 56 | 57 | std::cout << result; 58 | 59 | } catch (const std::exception &e) { 60 | std::cerr << e.what() << "\n"; 61 | return 1; 62 | } 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /examples/04-xslt/example.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /examples/04-xslt/example.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | root - 10 | 11 | 12 | 13 | 14 | child - 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/05-xpath/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | noinst_PROGRAMS=example 3 | 4 | example_SOURCES = example.cxx 5 | example_CPPFLAGS = -I$(top_srcdir)/include 6 | example_LDADD = ../../src/libxmlwrapp.la 7 | 8 | EXTRA_DIST = example.xml 9 | -------------------------------------------------------------------------------- /examples/05-xpath/example.cxx: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | // parse an example file 9 | xml::tree_parser parser("example.xml"); 10 | 11 | 12 | // instantiate an xpath-context 13 | // namespaces are registered here 14 | // with prefix and href. 15 | // see documentation for details 16 | xml::xpath_context ctxt(parser.get_document()); 17 | 18 | // execute the query //child (finds all "child"-nodes) 19 | xml::const_nodes_view children = ctxt.evaluate("//child"); 20 | 21 | // as you can see, node_set can be iterated over as any range. 22 | for (auto const& child : children) 23 | { 24 | std::cout << "//child : " << child.get_name() << std::endl; 25 | } 26 | 27 | for (auto const& child_with_attr : ctxt.evaluate("//child[@attrib=\"value\"]")) 28 | { 29 | std::cout << "//child[@attrib=\"value\"] : " << child_with_attr.get_name() << std::endl; 30 | } 31 | 32 | 33 | 34 | ctxt.register_namespace("p", "http://example.com/a"); 35 | 36 | const char *xpath = argc > 1 ? argv[1] : "/child/p:subchild"; 37 | for (auto const& subchild : ctxt.evaluate(xpath)) 38 | { 39 | std::cout << "/child/p:subchild : " << subchild.get_name() << std::endl; 40 | } 41 | 42 | 43 | return 0; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /examples/05-xpath/example.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /examples/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = \ 3 | 01-tree_parsing \ 4 | 02-event_parsing \ 5 | 03-xml_generation \ 6 | 04-xslt \ 7 | 05-xpath 8 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | xmlwrapp_includedir= $(includedir)/xmlwrapp 3 | xmlwrapp_include_HEADERS = \ 4 | xmlwrapp/attributes.h \ 5 | xmlwrapp/_cbfo.h \ 6 | xmlwrapp/document.h \ 7 | xmlwrapp/event_parser.h \ 8 | xmlwrapp/errors.h \ 9 | xmlwrapp/export.h \ 10 | xmlwrapp/init.h \ 11 | xmlwrapp/node.h \ 12 | xmlwrapp/nodes_view.h \ 13 | xmlwrapp/relaxng.h \ 14 | xmlwrapp/schema.h \ 15 | xmlwrapp/tree_parser.h \ 16 | xmlwrapp/version.h \ 17 | xmlwrapp/xmlwrapp.h \ 18 | xmlwrapp/xpath.h 19 | 20 | if WITH_XSLT 21 | xsltwrapp_includedir= $(includedir)/xsltwrapp 22 | xsltwrapp_include_HEADERS = \ 23 | xsltwrapp/init.h \ 24 | xsltwrapp/stylesheet.h \ 25 | xsltwrapp/xsltwrapp.h 26 | endif 27 | -------------------------------------------------------------------------------- /include/xmlwrapp/_cbfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org) 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef _xmlwrapp_cbfo_h_ 34 | #define _xmlwrapp_cbfo_h_ 35 | 36 | // xmlwrapp includes 37 | #include "xmlwrapp/export.h" 38 | 39 | namespace xml 40 | { 41 | 42 | class node; 43 | 44 | namespace impl 45 | { 46 | 47 | // helper for xml::node::sort() 48 | struct XMLWRAPP_API cbfo_node_compare 49 | { 50 | virtual ~cbfo_node_compare() = default; 51 | virtual bool operator()(const xml::node& lhs, const xml::node& rhs) = 0; 52 | }; 53 | 54 | template 55 | struct sort_callback : public cbfo_node_compare 56 | { 57 | sort_callback(T& t) : t_(t) {} 58 | 59 | bool operator()(const xml::node& lhs, const xml::node& rhs) override 60 | { return t_(lhs, rhs); } 61 | 62 | T &t_; 63 | }; 64 | 65 | } // namespace impl 66 | 67 | } // namespace xml 68 | 69 | #endif // _xmlwrapp_cbfo_h_ 70 | -------------------------------------------------------------------------------- /include/xmlwrapp/relaxng.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Vadim Zeitlin 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | /** 34 | @file 35 | 36 | This file contains the definition of the xml::relaxng class. 37 | */ 38 | 39 | #ifndef _xmlwrapp_relaxng_h_ 40 | #define _xmlwrapp_relaxng_h_ 41 | 42 | // xmlwrapp includes 43 | #include "xmlwrapp/init.h" 44 | #include "xmlwrapp/export.h" 45 | #include "xmlwrapp/errors.h" 46 | 47 | #include 48 | 49 | XMLWRAPP_MSVC_SUPPRESS_DLL_MEMBER_WARN 50 | 51 | namespace xml 52 | { 53 | 54 | // forward declarations 55 | class document; 56 | class error_messages; 57 | 58 | namespace impl 59 | { 60 | struct relaxng_impl; 61 | } 62 | 63 | /** 64 | XML validator using RelaxNG. 65 | 66 | This class is used to validate documents against RelaxNG schemas expressed 67 | in XML syntax (compact RelaxNG syntax is not supported). 68 | 69 | @since 0.9.0 70 | */ 71 | class XMLWRAPP_API relaxng 72 | { 73 | public: 74 | /** 75 | Parses XML RelaxNG document and creates relaxng instance from it. 76 | 77 | Errors are handled by @a on_error handler; by default, xml::exception 78 | is thrown on errors. If there's a fatal error that prevents the relaxng 79 | from being loaded and the error handler doesn't throw an exception, the 80 | constructor will throw xml::exception anyway. 81 | */ 82 | explicit relaxng(const document& doc, error_handler& on_error = throw_on_error); 83 | 84 | /// Destructor 85 | ~relaxng(); 86 | 87 | /** 88 | Validates the document @a doc against the relaxng. 89 | 90 | Errors are handled by @a on_error handler; by default, xml::exception 91 | is thrown on errors. 92 | 93 | @return `true` if the document is valid with regard to the relaxng, 94 | `false` otherwise. 95 | */ 96 | bool validate(const document& doc, error_handler& on_error = throw_on_error) const; 97 | 98 | private: 99 | std::unique_ptr pimpl_; 100 | 101 | // This class is not copyable 102 | relaxng(const relaxng&) = delete; 103 | relaxng& operator=(const relaxng&) = delete; 104 | }; 105 | 106 | } // namespace xml 107 | 108 | XMLWRAPP_MSVC_RESTORE_DLL_MEMBER_WARN 109 | 110 | #endif // _xmlwrapp_relaxng_h_ 111 | -------------------------------------------------------------------------------- /include/xmlwrapp/schema.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Vaclav Slavik 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | /** 34 | @file 35 | 36 | This file contains the definition of the xml::schema class. 37 | */ 38 | 39 | #ifndef _xmlwrapp_schema_h_ 40 | #define _xmlwrapp_schema_h_ 41 | 42 | // xmlwrapp includes 43 | #include "xmlwrapp/init.h" 44 | #include "xmlwrapp/export.h" 45 | #include "xmlwrapp/errors.h" 46 | 47 | #include 48 | 49 | XMLWRAPP_MSVC_SUPPRESS_DLL_MEMBER_WARN 50 | 51 | namespace xml 52 | { 53 | 54 | // forward declarations 55 | class document; 56 | class error_messages; 57 | 58 | namespace impl 59 | { 60 | struct schema_impl; 61 | } 62 | 63 | /** 64 | XML Schema. 65 | 66 | This class is used to validate documents against XML Schema. 67 | 68 | @since 0.7.0 69 | */ 70 | class XMLWRAPP_API schema 71 | { 72 | public: 73 | /** 74 | Parses XML Schema document and creates schema instance from it. 75 | 76 | Errors are handled by @a on_error handler; by default, xml::exception 77 | is thrown on errors. If there's a fatal error that prevents the schema 78 | from being loaded and the error handler doesn't throw an exception, the 79 | constructor will throw xml::exception anyway. 80 | */ 81 | explicit schema(const document& doc, error_handler& on_error = throw_on_error); 82 | 83 | /// Destructor 84 | ~schema(); 85 | 86 | /** 87 | Validates the document @a doc against the schema. 88 | 89 | Errors are handled by @a on_error handler; by default, xml::exception 90 | is thrown on errors. 91 | 92 | @return `true` if the document is valid with regard to the schema, 93 | `false` otherwise. 94 | */ 95 | bool validate(const document& doc, error_handler& on_error = throw_on_error) const; 96 | 97 | private: 98 | std::unique_ptr pimpl_; 99 | 100 | // Schema class is not copyable 101 | schema(const schema&) = delete; 102 | schema& operator=(const schema&) = delete; 103 | }; 104 | 105 | } // namespace xml 106 | 107 | XMLWRAPP_MSVC_RESTORE_DLL_MEMBER_WARN 108 | 109 | #endif // _xmlwrapp_schema_h_ 110 | -------------------------------------------------------------------------------- /include/xmlwrapp/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 Vaclav Slavik 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | /** 34 | @file 35 | 36 | This file contains the XMLWRAPP_CHECK_VERSION macro. 37 | */ 38 | 39 | #ifndef _xmlwrapp_version_h_ 40 | #define _xmlwrapp_version_h_ 41 | 42 | #define XMLWRAPP_VERSION_MAJOR 0 43 | #define XMLWRAPP_VERSION_MINOR 9 44 | #define XMLWRAPP_VERSION_MICRO 1 45 | 46 | /** 47 | Checks if xmlwrapp version is at least @a major.@a minor.@a micro. 48 | */ 49 | #define XMLWRAPP_CHECK_VERSION(major, minor, micro) \ 50 | ( \ 51 | XMLWRAPP_VERSION_MAJOR > (major) \ 52 | || \ 53 | (XMLWRAPP_VERSION_MAJOR == (major) && \ 54 | XMLWRAPP_VERSION_MINOR >= (minor)) \ 55 | || \ 56 | (XMLWRAPP_VERSION_MAJOR == (major) && \ 57 | (XMLWRAPP_VERSION_MINOR == (minor) && \ 58 | XMLWRAPP_VERSION_MICRO >= (micro)) \ 59 | ) 60 | 61 | #endif // _xmlwrapp_version_h_ 62 | -------------------------------------------------------------------------------- /include/xmlwrapp/xmlwrapp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org) 3 | * Copyright (C) 2013 Vaclav Slavik 4 | * All Rights Reserved 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name of the Author nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 23 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 24 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 27 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 30 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef _xmlwrapp_xmlwrapp_h_ 35 | #define _xmlwrapp_xmlwrapp_h_ 36 | 37 | #include "xmlwrapp/version.h" 38 | #include "xmlwrapp/init.h" 39 | #include "xmlwrapp/nodes_view.h" 40 | #include "xmlwrapp/node.h" 41 | #include "xmlwrapp/attributes.h" 42 | #include "xmlwrapp/document.h" 43 | #include "xmlwrapp/tree_parser.h" 44 | #include "xmlwrapp/event_parser.h" 45 | #include "xmlwrapp/errors.h" 46 | #include "xmlwrapp/relaxng.h" 47 | #include "xmlwrapp/schema.h" 48 | #include "xmlwrapp/xpath.h" 49 | 50 | #endif // _xmlwrapp_xmlwrapp_h_ 51 | -------------------------------------------------------------------------------- /include/xsltwrapp/init.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org) 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | /** 34 | @file 35 | 36 | This file contains the definition of the xslt::init class. 37 | */ 38 | 39 | #ifndef _xsltwrapp_init_h_ 40 | #define _xsltwrapp_init_h_ 41 | 42 | // xmlwrapp includes 43 | #include "xmlwrapp/init.h" 44 | #include "xmlwrapp/export.h" 45 | 46 | /// XSLT library namespace 47 | namespace xslt 48 | { 49 | 50 | /** 51 | The xslt::init class is used to configure the XSLT engine. 52 | 53 | If you want to use any of the xslt::init member functions, do so before 54 | you start any threads or use any other part of xsltwrapp. The member 55 | functions may alter global and/or static variables. In other words, this 56 | class is not thread safe. 57 | 58 | @note In xmlwrapp versions prior to 0.6.0, this class was used to initialize 59 | the library and exactly one instance had to be created before first 60 | use. This is no longer true: user code doesn't have to create any 61 | instances, but it @em can create as many instances as it wants. 62 | */ 63 | class init : public xml::init 64 | { 65 | public: 66 | XSLTWRAPP_API init(); 67 | XSLTWRAPP_API ~init(); 68 | 69 | /** 70 | This function controls whether or not the XSLT engine will process 71 | XInclusions by default while parsing the stylesheet. The default is 72 | true. 73 | 74 | @param flag True to enable XInclusing processing; False otherwise. 75 | */ 76 | XSLTWRAPP_API static void process_xincludes(bool flag); 77 | 78 | private: 79 | init(const init&) = delete; 80 | init& operator=(const init&) = delete; 81 | 82 | void init_library(); 83 | void shutdown_library(); 84 | 85 | static int ms_counter; 86 | }; // end xslt::init class 87 | 88 | 89 | // use a "nifty counter" to ensure that any source file that uses xsltwrapp 90 | // will initialize the library prior to its first use 91 | namespace 92 | { 93 | xslt::init g_xsltwrapp_initializer; 94 | } 95 | 96 | } // end xslt namespace 97 | 98 | #endif // _xsltwrapp_init_h_ 99 | -------------------------------------------------------------------------------- /include/xsltwrapp/xsltwrapp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org) 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef _xsltwrapp_xsltwrapp_h_ 34 | #define _xsltwrapp_xsltwrapp_h_ 35 | 36 | #include "xmlwrapp/xmlwrapp.h" 37 | #include "xsltwrapp/init.h" 38 | #include "xsltwrapp/stylesheet.h" 39 | 40 | #endif // _xsltwrapp_xsltwrapp_h_ 41 | -------------------------------------------------------------------------------- /platform/Win32/README: -------------------------------------------------------------------------------- 1 | This directory contains the projects for building the library with Microsoft 2 | Visual C++. 3 | 4 | Please see comments in libxml.props for configuring the location of the 5 | required XML libraries. 6 | 7 | You will need to use Bakefile (http://www.bakefile.org) to regenerate these 8 | projects, but you don't need it to simply use them. 9 | 10 | 11 | For convience, master.proj msbuild project is included. This downloads all 12 | dependencies. It requires MSBuild.Community.Tasks from 13 | http://msbuildtasks.tigris.org/ (just install the MSI package). 14 | -------------------------------------------------------------------------------- /platform/Win32/libxml.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <_PropertySheetDisplayName>XML libraries 5 | 6 | 7 | 17 | 18 | $(MSBuildThisFileDirectory) 19 | 20 | 21 | 22 | 23 | $(XMLLIBS_DIR) 24 | 25 | 26 | 27 | 28 | 29 | $(XMLLIBS_DIR)\include\libxml2;$(XMLLIBS_DIR)\include;%(AdditionalIncludeDirectories) 30 | 31 | 32 | $(XMLLIBS_DIR)\lib\$(Platform);%(AdditionalLibraryDirectories) 33 | 34 | 35 | 36 | 37 | 40 | 43 | 46 | 49 | 52 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /platform/Win32/master.proj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 7 | 8 | 1.2.5 9 | 1.9.2 10 | 2.7.8 11 | 1.1.26 12 | 13 | 14 | 15 | ftp://ftp.zlatkovic.com/libxml 16 | zlib-$(VersionZlib).win32 17 | iconv-$(VersionIconv).win32 18 | libxml2-$(VersionLibxml2).win32 19 | libxslt-$(VersionLibxslt).win32 20 | $(DirZlib).zip 21 | $(DirIconv).zip 22 | $(DirLibxml2).zip 23 | $(DirLibxslt).zip 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 38 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 53 | 56 | 59 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /platform/Win32/test.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 4 | 5 | 6 | 7 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 8 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 9 | 10 | 11 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 12 | h;hpp;hxx;hm;inl;inc;xsd 13 | 14 | 15 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 16 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 17 | 18 | 19 | 20 | 21 | Header Files 22 | 23 | 24 | 25 | 26 | Source Files 27 | 28 | 29 | Source Files 30 | 31 | 32 | Source Files 33 | 34 | 35 | Source Files 36 | 37 | 38 | Source Files 39 | 40 | 41 | Source Files 42 | 43 | 44 | Source Files 45 | 46 | 47 | Source Files 48 | 49 | 50 | Source Files 51 | 52 | 53 | Source Files 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /platform/Win32/xmlwrapp.bkl: -------------------------------------------------------------------------------- 1 | // 2 | // Bakefile for xmlwrapp Windows builds. This file needs to be processed with 3 | // Bakefile 1.x, see http://www.bakefile.org. 4 | // 5 | 6 | srcdir ../..; 7 | toolsets = msvs; 8 | 9 | WIN32_DIR = platform/Win32; 10 | 11 | msvs.solutionfile = $(WIN32_DIR)/xmlwrapp.sln; 12 | 13 | vs.property-sheets = $(WIN32_DIR)/libxml.props; 14 | 15 | archs = x86 x86_64; 16 | 17 | // By default Win32 files don't use platform in their path, get rid of this 18 | // historical inconsistency. 19 | outputdir = $(WIN32_DIR)/$(arch)/$(config); 20 | 21 | includedirs += include; 22 | 23 | // Disable many warnings about the deprecated standard functions for all 24 | // MSVS versions since 2005 that introduced them. 25 | defines += _CRT_SECURE_NO_DEPRECATE 26 | _CRT_SECURE_NO_WARNINGS 27 | _CRT_NONSTDC_NO_WARNINGS 28 | _SCL_SECURE_NO_WARNINGS; 29 | 30 | 31 | warnings = all; 32 | 33 | shared-library xmlwrapp { 34 | libs = libxml2; 35 | 36 | defines += DLL_EXPORT XMLWRAPP_BUILD; 37 | 38 | headers { 39 | include/xmlwrapp/attributes.h 40 | include/xmlwrapp/_cbfo.h 41 | include/xmlwrapp/document.h 42 | include/xmlwrapp/event_parser.h 43 | include/xmlwrapp/errors.h 44 | include/xmlwrapp/init.h 45 | include/xmlwrapp/node.h 46 | include/xmlwrapp/nodes_view.h 47 | include/xmlwrapp/relaxng.h 48 | include/xmlwrapp/schema.h 49 | include/xmlwrapp/tree_parser.h 50 | include/xmlwrapp/xpath.h 51 | include/xmlwrapp/xmlwrapp.h 52 | 53 | // private headers: 54 | src/libxml/ait_impl.h 55 | src/libxml/dtd_impl.h 56 | src/libxml/errors_impl.h 57 | src/libxml/node_iterator.h 58 | src/libxml/node_manip.h 59 | src/libxml/utility.h 60 | } 61 | 62 | sources { 63 | src/libxml/ait_impl.cxx 64 | src/libxml/attributes.cxx 65 | src/libxml/document.cxx 66 | src/libxml/dtd_impl.cxx 67 | src/libxml/event_parser.cxx 68 | src/libxml/errors.cxx 69 | src/libxml/init.cxx 70 | src/libxml/node.cxx 71 | src/libxml/node_iterator.cxx 72 | src/libxml/node_manip.cxx 73 | src/libxml/nodes_view.cxx 74 | src/libxml/relaxng.cxx 75 | src/libxml/schema.cxx 76 | src/libxml/tree_parser.cxx 77 | src/libxml/utility.cxx 78 | src/libxml/xpath.cxx 79 | } 80 | } 81 | 82 | shared-library xsltwrapp { 83 | deps = xmlwrapp; 84 | 85 | libs = libexslt libxslt libxml2; 86 | 87 | defines += DLL_EXPORT XSLTWRAPP_BUILD; 88 | 89 | headers { 90 | include/xsltwrapp/init.h 91 | include/xsltwrapp/stylesheet.h 92 | include/xsltwrapp/xsltwrapp.h 93 | 94 | // private headers: 95 | src/libxslt/result.h 96 | } 97 | 98 | sources { 99 | src/libxslt/init.cxx 100 | src/libxslt/stylesheet.cxx 101 | } 102 | } 103 | 104 | program test { 105 | includedirs = include; 106 | 107 | deps = xmlwrapp xsltwrapp; 108 | 109 | defines += XMLWRAPP_USE_DLL; 110 | 111 | headers { 112 | tests/test.h 113 | } 114 | 115 | sources { 116 | tests/test_main.cxx 117 | tests/attributes/test_attributes.cxx 118 | tests/document/test_document.cxx 119 | tests/event/test_event.cxx 120 | tests/node/test_node.cxx 121 | tests/relaxng/test_relaxng.cxx 122 | tests/schema/test_schema.cxx 123 | tests/tree/test_tree.cxx 124 | tests/xpath/test_xpath.cxx 125 | tests/xslt/test_xslt.cxx 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /platform/Win32/xmlwrapp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 17 4 | VisualStudioVersion = 17.0.31919.166 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xmlwrapp", "xmlwrapp.vcxproj", "{27D0067A-8534-56E2-A734-799F4A6CE894}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xsltwrapp", "xsltwrapp.vcxproj", "{30E912D3-2B6D-5358-81F3-7CF96781F735}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {27D0067A-8534-56E2-A734-799F4A6CE894} = {27D0067A-8534-56E2-A734-799F4A6CE894} 11 | EndProjectSection 12 | EndProject 13 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test.vcxproj", "{C824FD57-A9D0-5288-9677-F80D927BC942}" 14 | ProjectSection(ProjectDependencies) = postProject 15 | {27D0067A-8534-56E2-A734-799F4A6CE894} = {27D0067A-8534-56E2-A734-799F4A6CE894} 16 | {30E912D3-2B6D-5358-81F3-7CF96781F735} = {30E912D3-2B6D-5358-81F3-7CF96781F735} 17 | EndProjectSection 18 | EndProject 19 | Global 20 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 21 | Debug|Win32 = Debug|Win32 22 | Debug|x64 = Debug|x64 23 | Release|Win32 = Release|Win32 24 | Release|x64 = Release|x64 25 | EndGlobalSection 26 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 27 | {27D0067A-8534-56E2-A734-799F4A6CE894}.Debug|Win32.ActiveCfg = Debug|Win32 28 | {27D0067A-8534-56E2-A734-799F4A6CE894}.Debug|Win32.Build.0 = Debug|Win32 29 | {27D0067A-8534-56E2-A734-799F4A6CE894}.Debug|x64.ActiveCfg = Debug|x64 30 | {27D0067A-8534-56E2-A734-799F4A6CE894}.Debug|x64.Build.0 = Debug|x64 31 | {27D0067A-8534-56E2-A734-799F4A6CE894}.Release|Win32.ActiveCfg = Release|Win32 32 | {27D0067A-8534-56E2-A734-799F4A6CE894}.Release|Win32.Build.0 = Release|Win32 33 | {27D0067A-8534-56E2-A734-799F4A6CE894}.Release|x64.ActiveCfg = Release|x64 34 | {27D0067A-8534-56E2-A734-799F4A6CE894}.Release|x64.Build.0 = Release|x64 35 | {30E912D3-2B6D-5358-81F3-7CF96781F735}.Debug|Win32.ActiveCfg = Debug|Win32 36 | {30E912D3-2B6D-5358-81F3-7CF96781F735}.Debug|Win32.Build.0 = Debug|Win32 37 | {30E912D3-2B6D-5358-81F3-7CF96781F735}.Debug|x64.ActiveCfg = Debug|x64 38 | {30E912D3-2B6D-5358-81F3-7CF96781F735}.Debug|x64.Build.0 = Debug|x64 39 | {30E912D3-2B6D-5358-81F3-7CF96781F735}.Release|Win32.ActiveCfg = Release|Win32 40 | {30E912D3-2B6D-5358-81F3-7CF96781F735}.Release|Win32.Build.0 = Release|Win32 41 | {30E912D3-2B6D-5358-81F3-7CF96781F735}.Release|x64.ActiveCfg = Release|x64 42 | {30E912D3-2B6D-5358-81F3-7CF96781F735}.Release|x64.Build.0 = Release|x64 43 | {C824FD57-A9D0-5288-9677-F80D927BC942}.Debug|Win32.ActiveCfg = Debug|Win32 44 | {C824FD57-A9D0-5288-9677-F80D927BC942}.Debug|Win32.Build.0 = Debug|Win32 45 | {C824FD57-A9D0-5288-9677-F80D927BC942}.Debug|x64.ActiveCfg = Debug|x64 46 | {C824FD57-A9D0-5288-9677-F80D927BC942}.Debug|x64.Build.0 = Debug|x64 47 | {C824FD57-A9D0-5288-9677-F80D927BC942}.Release|Win32.ActiveCfg = Release|Win32 48 | {C824FD57-A9D0-5288-9677-F80D927BC942}.Release|Win32.Build.0 = Release|Win32 49 | {C824FD57-A9D0-5288-9677-F80D927BC942}.Release|x64.ActiveCfg = Release|x64 50 | {C824FD57-A9D0-5288-9677-F80D927BC942}.Release|x64.Build.0 = Release|x64 51 | EndGlobalSection 52 | GlobalSection(SolutionProperties) = preSolution 53 | HideSolutionNode = FALSE 54 | EndGlobalSection 55 | EndGlobal 56 | -------------------------------------------------------------------------------- /platform/Win32/xmlwrapp.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 4 | 5 | 6 | 7 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 8 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 9 | 10 | 11 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 12 | h;hpp;hxx;hm;inl;inc;xsd 13 | 14 | 15 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 16 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 17 | 18 | 19 | 20 | 21 | Header Files 22 | 23 | 24 | Header Files 25 | 26 | 27 | Header Files 28 | 29 | 30 | Header Files 31 | 32 | 33 | Header Files 34 | 35 | 36 | Header Files 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | Header Files 55 | 56 | 57 | Header Files 58 | 59 | 60 | Header Files 61 | 62 | 63 | Header Files 64 | 65 | 66 | Header Files 67 | 68 | 69 | Header Files 70 | 71 | 72 | Header Files 73 | 74 | 75 | Header Files 76 | 77 | 78 | 79 | 80 | Source Files 81 | 82 | 83 | Source Files 84 | 85 | 86 | Source Files 87 | 88 | 89 | Source Files 90 | 91 | 92 | Source Files 93 | 94 | 95 | Source Files 96 | 97 | 98 | Source Files 99 | 100 | 101 | Source Files 102 | 103 | 104 | Source Files 105 | 106 | 107 | Source Files 108 | 109 | 110 | Source Files 111 | 112 | 113 | Source Files 114 | 115 | 116 | Source Files 117 | 118 | 119 | Source Files 120 | 121 | 122 | Source Files 123 | 124 | 125 | Source Files 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /platform/Win32/xsltwrapp.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 4 | 5 | 6 | 7 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 8 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 9 | 10 | 11 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 12 | h;hpp;hxx;hm;inl;inc;xsd 13 | 14 | 15 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 16 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 17 | 18 | 19 | 20 | 21 | Header Files 22 | 23 | 24 | Header Files 25 | 26 | 27 | Header Files 28 | 29 | 30 | Header Files 31 | 32 | 33 | 34 | 35 | Source Files 36 | 37 | 38 | Source Files 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /scripts/ci/common.sh: -------------------------------------------------------------------------------- 1 | # This file is not executable and is only sourced by the other scripts. 2 | 3 | # Default setting of CC=gcc and CXX=g++ results in the native compiler being 4 | # picked even when cross-compiling, which breaks the build, so unset these 5 | # variables in this case (we could also set them to $HOST-gcc...). 6 | if [ -n "$HOST" ]; then 7 | unset CC 8 | unset CXX 9 | fi 10 | -------------------------------------------------------------------------------- /scripts/ci/install-debian.sh: -------------------------------------------------------------------------------- 1 | # Used to install dependencies for the CI builds under Debian/Ubuntu. 2 | 3 | # Arch-independent dependencies. 4 | sudo apt-get update -qq 5 | 6 | # We only build documentation in the build from the distribution archive. 7 | if [ "$TEST_DIST" = 1 ]; then 8 | sudo apt-get install -qq --no-install-recommends doxygen graphviz 9 | fi 10 | 11 | case "$HOST" in 12 | *-w64-mingw32) 13 | arch=`echo $HOST | sed -e 's/-w64-mingw32$//;s/_/-/'` 14 | 15 | case "$arch" in 16 | i686) 17 | sudo dpkg --add-architecture i386 18 | 19 | # Workaround for https://github.com/actions/runner-images/issues/4589 20 | # (normally only apt-get update should have been needed) 21 | sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list 22 | sudo apt-get update -qq 23 | sudo apt-get remove -qq libmono* moby* mono* nginx* php* libgdiplus libpcre2-posix3 libzip4 24 | 25 | wine_package=wine32-development 26 | ;; 27 | 28 | x86-64) 29 | wine_package=wine64-development 30 | ;; 31 | 32 | *) 33 | echo "Unknown architecture $arch when cross-compiling" 34 | exit 1 35 | ;; 36 | esac 37 | 38 | sudo apt-get update 39 | sudo apt-get install -qq --no-install-recommends g++-mingw-w64-$arch \ 40 | $wine_package wine-development 41 | 42 | echo -n "Cross-compiling for $HOST using " 43 | $HOST-g++ --version 44 | 45 | # Download the previously built required dependencies. 46 | wget --no-verbose https://github.com/vslavik/xmlwrapp/releases/download/xmllibs/xmllibs-${HOST}.zip 47 | sudo unzip -q xmllibs-${HOST}.zip -d /usr/local 48 | ;; 49 | 50 | *) 51 | # Assume native build. 52 | sudo apt-get install -qq libxml2-dev libxslt1-dev 53 | ;; 54 | esac 55 | -------------------------------------------------------------------------------- /scripts/ci/install-macos.sh: -------------------------------------------------------------------------------- 1 | # Used to install dependencies for the CI builds under macOS. 2 | 3 | brew install autoconf automake doxygen graphviz 4 | -------------------------------------------------------------------------------- /scripts/ci/install-redhat.sh: -------------------------------------------------------------------------------- 1 | # Used to install dependencies for the CI builds under CentOS/Fedora. 2 | 3 | sudo yum -y install libxml2-devel libxslt-devel 4 | -------------------------------------------------------------------------------- /scripts/ci/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Used to install dependencies for the CI builds. 3 | set -e 4 | 5 | . ${XMLWRAPP_SOURCE_DIR}/scripts/ci/common.sh 6 | 7 | case $(uname -s) in 8 | Linux) 9 | if [ -f /etc/apt/sources.list ]; then 10 | platform=debian 11 | elif [ -f /etc/redhat-release ]; then 12 | platform=redhat 13 | else 14 | echo 'Unknown Linux distribution.' >&2 15 | exit 1 16 | fi 17 | ;; 18 | 19 | Darwin) 20 | platform=macos 21 | ;; 22 | 23 | *) 24 | echo "Unknown platform `uname`." >&2 25 | exit 1 26 | esac 27 | 28 | . ${XMLWRAPP_SOURCE_DIR}/scripts/ci/install-${platform}.sh 29 | -------------------------------------------------------------------------------- /scripts/ci/script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Main build script for the CI builds. 3 | set -e 4 | 5 | . ${XMLWRAPP_SOURCE_DIR}/scripts/ci/common.sh 6 | 7 | autoreconf --symlink --install 8 | 9 | CXXFLAGS="-Werror $CXXFLAGS" 10 | 11 | case "$HOST" in 12 | *-mingw*) 13 | configure_args="--host=$HOST" 14 | 15 | # As long as we don't have any other tests (e.g. written in interpreted 16 | # language), just setting LOG_COMPILER to Wine is good enough. If we do 17 | # need to run e.g. Python tests too, we would need a script selecting the 18 | # right way to run the test depending on its extension as, unfortunately, 19 | # setting EXE_LOG_COMPILER doesn't work (although PY_LOG_COMPILER does). 20 | export LOG_COMPILER=wine-development 21 | 22 | # Set up the path to allow the tests to find libstdc++ and libxml2 DLLs. 23 | export WINEPATH="$(dirname $($HOST-g++ -print-libgcc-file-name));/usr/local/bin" 24 | ;; 25 | esac 26 | 27 | if [ "$TEST_DIST" != 1 ]; then 28 | configure_args="$configure_args --disable-docs" 29 | fi 30 | 31 | ./configure CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS" $configure_args 32 | 33 | # Test building from a distribution archive, rather than from Git sources. 34 | if [ "$TEST_DIST" = 1 ]; then 35 | # We need bkl in order to build the distribution archives, so get it. 36 | BKL_VERSION=1.2.6 37 | BKL_ARCHIVE=bakefile-${BKL_VERSION}-bin.tar.bz2 38 | 39 | wget --no-verbose https://github.com/vslavik/bakefile/releases/download/v${BKL_VERSION}/${BKL_ARCHIVE} 40 | 41 | # We assume we're using GNU tar, which can uncompress .bz2 files on its own. 42 | tar xf ${BKL_ARCHIVE} 43 | 44 | PATH=$(pwd)/bakefile-${BKL_VERSION}:${PATH} 45 | 46 | make distcheck DISTCHECK_CONFIGURE_FLAGS="$configure_args" 47 | 48 | # No need to build and test again, this is already done by distcheck. 49 | exit 0 50 | fi 51 | 52 | make --keep-going 53 | 54 | if ! make check; then 55 | echo 'Test suite log contents' 56 | echo '-----------------------' 57 | cat tests/test-suite.log 58 | echo '-----------------------' 59 | exit 1 60 | fi 61 | -------------------------------------------------------------------------------- /scripts/install_deps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Script installing the dependencies for this library. 3 | # 4 | # It is used by the CI scripts, but could be used directly if these libraries 5 | # are not available as packages on your system. 6 | # 7 | # Note that the script makes no attempt to clean up after itself and assumes 8 | # it can use sudo to install the libraries to /usr/local. 9 | set -e 10 | 11 | # Takes base name of the library, its version and an arbitrary number of 12 | # arguments to pass to the library configure. 13 | install_lib() { 14 | lib_basename=$1-$2 15 | shift 16 | shift 17 | lib_archive=$lib_basename.tar.gz 18 | 19 | [ -e $lib_archive ] || wget http://xmlsoft.org/sources/$lib_archive 20 | tar xzf $lib_archive 21 | cd $lib_basename 22 | # Use minimal and build maximally self-contained library. 23 | configure_args='--disable-dependency-tracking --disable-static --without-python' 24 | if [ -n "$HOST" ]; then 25 | configure_args="$configure_args --host=$HOST" 26 | fi 27 | mkdir build-${HOST-native} 28 | cd build-${HOST-native} 29 | ../configure $configure_args "$@" 30 | 31 | # Note that we can't just set LDFLAGS to -static-libgcc during configure 32 | # because they end up in the generated libtool and libtool then simply 33 | # silently discards this "unknown" (to it) flag. And while libtool would 34 | # pass on the -Wc,xxx flag, we can't use it as it prevents configure tests 35 | # from working. So instead we pass it to make, where libtool does add it 36 | # to the linker command line, ensuring that we link runtime libraries 37 | # statically, as we want. 38 | # 39 | # Also, there is a bug in libxslt configure in all versions in [1.1.34, 40 | # 1.1.37] range which incorrectly set LDFLAGS to "-no-undefined" in 41 | # configure, so we have to use this option too (it's always required for 42 | # Win32 DLLs). 43 | make --no-print-directory -j`nproc` LDFLAGS='-Wc,-static-libgcc -no-undefined' 44 | ${SUDO-sudo} make --no-print-directory install 45 | cd ../.. 46 | } 47 | 48 | install_lib libxml2 2.9.12 --without-lzma --without-modules --without-zlib 49 | install_lib libxslt 1.1.34 --without-crypto 50 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | AM_CPPFLAGS = -I$(top_srcdir)/include $(CXXFLAGS_VISIBILITY) 3 | 4 | if WITH_XSLT 5 | lib_LTLIBRARIES = libxmlwrapp.la libxsltwrapp.la 6 | else 7 | lib_LTLIBRARIES = libxmlwrapp.la 8 | endif 9 | 10 | libxmlwrapp_la_CPPFLAGS = -DXMLWRAPP_BUILD $(AM_CPPFLAGS) $(LIBXML_CFLAGS) 11 | libxmlwrapp_la_LIBADD = $(LIBXML_LIBS) 12 | libxmlwrapp_la_LDFLAGS = -version-info 6:0:0 -no-undefined 13 | 14 | libxmlwrapp_la_SOURCES = \ 15 | libxml/ait_impl.cxx \ 16 | libxml/ait_impl.h \ 17 | libxml/attributes.cxx \ 18 | libxml/document.cxx \ 19 | libxml/dtd_impl.cxx \ 20 | libxml/dtd_impl.h \ 21 | libxml/event_parser.cxx \ 22 | libxml/errors.cxx \ 23 | libxml/errors_impl.h \ 24 | libxml/init.cxx \ 25 | libxml/node.cxx \ 26 | libxml/nodes_view.cxx \ 27 | libxml/node_iterator.cxx \ 28 | libxml/node_iterator.h \ 29 | libxml/node_manip.cxx \ 30 | libxml/node_manip.h \ 31 | libxml/relaxng.cxx \ 32 | libxml/schema.cxx \ 33 | libxml/tree_parser.cxx \ 34 | libxml/utility.cxx \ 35 | libxml/utility.h \ 36 | libxml/xpath.cxx 37 | 38 | 39 | if WITH_XSLT 40 | 41 | libxsltwrapp_la_CPPFLAGS = -DXSLTWRAPP_BUILD -DXMLWRAPP_USE_DLL $(AM_CPPFLAGS) $(LIBEXSLT_CFLAGS) $(LIBXSLT_CFLAGS) 42 | libxsltwrapp_la_LIBADD = libxmlwrapp.la $(LIBEXSLT_LIBS) $(LIBXSLT_LIBS) 43 | libxsltwrapp_la_LDFLAGS = -version-info 4:0:0 -no-undefined 44 | 45 | libxsltwrapp_la_SOURCES = \ 46 | libxslt/init.cxx \ 47 | libxslt/result.h \ 48 | libxslt/stylesheet.cxx 49 | 50 | endif 51 | -------------------------------------------------------------------------------- /src/libxml/ait_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org) 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef _xmlwrapp_ait_impl_h_ 34 | #define _xmlwrapp_ait_impl_h_ 35 | 36 | // xmlwrapp includes 37 | #include "xmlwrapp/attributes.h" 38 | 39 | // libxml2 includes 40 | #include 41 | 42 | namespace xml 43 | { 44 | 45 | namespace impl 46 | { 47 | 48 | // The class that does all the work behind xml::attributes::iterator and 49 | // xml::attributes::const_iterator. 50 | class ait_impl 51 | { 52 | public: 53 | ait_impl(xmlNodePtr node, xmlAttrPtr prop); 54 | ait_impl(const char *name, const char *value, bool); 55 | ait_impl(const ait_impl& other); 56 | ait_impl& operator=(const ait_impl& other); 57 | 58 | attributes::attr* get(); 59 | xmlAttrPtr get_raw_attr(); 60 | 61 | ait_impl& operator++(); 62 | ait_impl operator++(int); 63 | 64 | friend bool operator==(const ait_impl& lhs, const ait_impl& rhs); 65 | friend bool operator!=(const ait_impl& lhs, const ait_impl& rhs); 66 | 67 | private: 68 | xmlNodePtr xmlnode_; 69 | xmlAttrPtr xmlattr_; 70 | attributes::attr attr_; 71 | bool fake_; 72 | }; 73 | 74 | // a couple helper functions 75 | xmlAttrPtr find_prop(xmlNodePtr xmlnode, const char *name); 76 | xmlAttributePtr find_default_prop(xmlNodePtr xmlnode, const char *name); 77 | 78 | } // namespace impl 79 | 80 | } // namespace xml 81 | 82 | #endif // _xmlwrapp_ait_impl_h_ 83 | -------------------------------------------------------------------------------- /src/libxml/dtd_impl.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org) 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | // xmlwrapp includes 34 | #include "dtd_impl.h" 35 | #include "utility.h" 36 | 37 | // standard includes 38 | #include 39 | #include 40 | 41 | // libxml2 includes 42 | #include 43 | #include 44 | #include 45 | 46 | using namespace xml; 47 | using namespace xml::impl; 48 | 49 | namespace 50 | { 51 | 52 | extern "C" void dtd_error(void *ctxt, const char *message, ...) 53 | { 54 | auto *dtd = static_cast(ctxt); 55 | 56 | va_list ap; 57 | va_start(ap, message); 58 | printf2string(dtd->error_, message, ap); 59 | va_end(ap); 60 | } 61 | 62 | extern "C" void dtd_warning(void *ctxt, const char*, ...) 63 | { 64 | auto *dtd = static_cast(ctxt); 65 | ++dtd->warnings_; 66 | } 67 | 68 | } // anonymous namespace 69 | 70 | 71 | dtd_impl::dtd_impl(const char *filename) 72 | : warnings_(0), dtd_(nullptr) 73 | { 74 | if ( (dtd_ = xmlParseDTD(nullptr, reinterpret_cast(filename))) == nullptr) 75 | { 76 | error_ = "unable to parse DTD "; 77 | error_ += filename; 78 | } 79 | } 80 | 81 | 82 | dtd_impl::dtd_impl() : warnings_(0), dtd_(nullptr) 83 | { 84 | } 85 | 86 | 87 | dtd_impl::~dtd_impl() 88 | { 89 | if (dtd_) 90 | xmlFreeDtd(dtd_); 91 | } 92 | 93 | 94 | void dtd_impl::init_ctxt() 95 | { 96 | std::memset(&vctxt_, 0, sizeof(vctxt_)); 97 | 98 | vctxt_.userData = this; 99 | vctxt_.error = dtd_error; 100 | vctxt_.warning = dtd_warning; 101 | } 102 | 103 | 104 | bool dtd_impl::validate(xmlDocPtr xmldoc) 105 | { 106 | init_ctxt(); 107 | 108 | if (dtd_) 109 | return xmlValidateDtd(&vctxt_, xmldoc, dtd_) != 0; 110 | else 111 | return xmlValidateDocument(&vctxt_, xmldoc) != 0; 112 | } 113 | 114 | 115 | xmlDtdPtr dtd_impl::release() 116 | { 117 | xmlDtdPtr xmldtd = dtd_; 118 | dtd_ = nullptr; 119 | return xmldtd; 120 | } 121 | -------------------------------------------------------------------------------- /src/libxml/dtd_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org) 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef _xmlwrapp_dtd_impl_h_ 34 | #define _xmlwrapp_dtd_impl_h_ 35 | 36 | // standard includes 37 | #include 38 | 39 | // libxml2 includes 40 | #include 41 | #include 42 | #include 43 | 44 | namespace xml 45 | { 46 | 47 | namespace impl 48 | { 49 | 50 | class dtd_impl 51 | { 52 | public: 53 | // load the given DTD. you should check to see if error_ is empty or 54 | // not, which will tell you if the DTD was loaded okay. 55 | explicit dtd_impl(const char *filename); 56 | 57 | // Don't load a DTD 58 | dtd_impl(); 59 | 60 | ~dtd_impl(); 61 | 62 | // check the document against the loaded DTD, or in the case where no 63 | // DTD is loaded try to use the one inside the document. 64 | bool validate(xmlDocPtr xmldoc); 65 | 66 | // return the dtd pointer and never again free it. 67 | xmlDtdPtr release(); 68 | 69 | // count of DTD parsing/validating warnings 70 | int warnings_; 71 | 72 | // last DTD parsing/validating error message 73 | std::string error_; 74 | 75 | private: 76 | xmlValidCtxt vctxt_; 77 | xmlDtdPtr dtd_; 78 | 79 | dtd_impl(const dtd_impl&) = delete; 80 | dtd_impl& operator=(const dtd_impl&) = delete; 81 | void init_ctxt(); 82 | }; 83 | 84 | } // namespace impl 85 | 86 | } // namespace xml 87 | 88 | #endif // _xmlwrapp_dtd_impl_h_ 89 | -------------------------------------------------------------------------------- /src/libxml/errors_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Vaclav Slavik 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef _xmlwrapp_errors_impl_h_ 34 | #define _xmlwrapp_errors_impl_h_ 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | namespace xml 41 | { 42 | 43 | namespace impl 44 | { 45 | 46 | // This handler collects all error & warning messages from libxml2 callbacks, 47 | // without throwing any exceptions, and then replays them, in order, to the 48 | // "real" error handler. 49 | class XMLWRAPP_API errors_collector : public error_messages 50 | { 51 | public: 52 | // replay all errors into target handler 53 | void replay(error_handler& dest); 54 | 55 | protected: 56 | std::string format_for_print(const error_message& msg) const override; 57 | }; 58 | 59 | // RAII helper installing the given error collector as the global error sink 60 | // for libxml2 error messages. 61 | class XMLWRAPP_API global_errors_installer 62 | { 63 | public: 64 | // The object given as argument must have lifetime greater than that of 65 | // this object itself. 66 | explicit global_errors_installer(error_messages& on_error); 67 | ~global_errors_installer(); 68 | 69 | private: 70 | global_errors_installer(const global_errors_installer&) = delete; 71 | global_errors_installer& operator=(const global_errors_installer&) = delete; 72 | 73 | xmlGenericErrorFunc xml_generic_error_orig_; 74 | void *xml_generic_error_context_orig_; 75 | 76 | xmlStructuredErrorFunc xml_structured_error_orig_; 77 | void *xml_structured_error_context_orig_; 78 | }; 79 | 80 | // This class behaves like error_collector but also installs itself as handler 81 | // for global libxml2 errors, i.e. those that happen outside of any other 82 | // context. 83 | class global_errors_collector : 84 | public errors_collector, 85 | private global_errors_installer 86 | { 87 | public: 88 | global_errors_collector() : 89 | global_errors_installer(static_cast(*this)) 90 | { 91 | } 92 | 93 | private: 94 | global_errors_collector(const global_errors_collector&) = delete; 95 | global_errors_collector& operator=(const global_errors_collector&) = delete; 96 | }; 97 | 98 | // These functions can be used as error callbacks in various libxml2 functions. 99 | // They collect messages into errors_collector structure. 100 | // Usage: pass the pointer to errors_collector as libxml2's void* ctx argument 101 | extern "C" 102 | { 103 | 104 | #if LIBXML_VERSION >= 21200 105 | XMLWRAPP_API void cb_messages_structured_error(void *out, const xmlError *error); 106 | #else 107 | XMLWRAPP_API void cb_messages_structured_error(void *out, xmlErrorPtr error); 108 | #endif 109 | 110 | XMLWRAPP_API void cb_messages_warning(void *out, const char *message, ...); 111 | XMLWRAPP_API void cb_messages_error(void *out, const char *message, ...); 112 | 113 | XMLWRAPP_API void cb_messages_warning_v(void *out, const char *message, va_list ap); 114 | XMLWRAPP_API void cb_messages_error_v(void *out, const char *message, va_list ap); 115 | 116 | #define CALL_CB_MESSAGES(cb, out, message) \ 117 | va_list ap; \ 118 | va_start(ap, message); \ 119 | cb(out, message, ap); \ 120 | va_end(ap) 121 | 122 | #define CALL_CB_MESSAGES_ERROR(out, message) \ 123 | CALL_CB_MESSAGES(cb_messages_error_v, out, message) 124 | 125 | #define CALL_CB_MESSAGES_WARNING(out, message) \ 126 | CALL_CB_MESSAGES(cb_messages_warning_v, out, message) 127 | 128 | } // extern "C" 129 | 130 | } // namespace impl 131 | 132 | } // namespace xml 133 | 134 | 135 | #endif // _xmlwrapp_errors_impl_h_ 136 | -------------------------------------------------------------------------------- /src/libxml/init.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org) 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | 34 | // xmlwrapp includes 35 | #include "xmlwrapp/init.h" 36 | 37 | // libxml includes 38 | #include 39 | #include 40 | #include 41 | 42 | namespace 43 | { 44 | 45 | bool change_flag_and_return_old_value(int* flag, bool new_value) 46 | { 47 | const bool old_value = *flag != 0; 48 | *flag = new_value ? 1 : 0; 49 | return old_value; 50 | } 51 | 52 | } // anonymous namespace 53 | 54 | namespace xml 55 | { 56 | 57 | int init::ms_counter = 0; 58 | 59 | init::init() 60 | { 61 | if ( ms_counter++ == 0 ) 62 | init_library(); 63 | } 64 | 65 | 66 | init::~init() 67 | { 68 | if ( --ms_counter == 0 ) 69 | shutdown_library(); 70 | } 71 | 72 | 73 | void init::init_library() 74 | { 75 | // init the parser (keeps libxml2 thread safe) 76 | xmlInitParser(); 77 | 78 | // set some libxml global variables 79 | indent_output(true); 80 | remove_whitespace(false); 81 | substitute_entities(true); 82 | load_external_subsets(true); 83 | validate_xml(false); 84 | } 85 | 86 | 87 | void init::shutdown_library() 88 | { 89 | xmlCleanupParser(); 90 | } 91 | 92 | 93 | bool init::indent_output(bool flag) 94 | { 95 | return change_flag_and_return_old_value(&xmlIndentTreeOutput, flag); 96 | } 97 | 98 | 99 | bool init::remove_whitespace(bool flag) 100 | { 101 | return !change_flag_and_return_old_value(&xmlKeepBlanksDefaultValue, !flag); 102 | } 103 | 104 | 105 | bool init::substitute_entities(bool flag) 106 | { 107 | return change_flag_and_return_old_value(&xmlSubstituteEntitiesDefaultValue, flag); 108 | } 109 | 110 | 111 | bool init::load_external_subsets(bool flag) 112 | { 113 | return change_flag_and_return_old_value(&xmlLoadExtDtdDefaultValue, flag); 114 | } 115 | 116 | 117 | bool init::validate_xml(bool flag) 118 | { 119 | return change_flag_and_return_old_value(&xmlDoValidityCheckingDefaultValue, flag); 120 | } 121 | 122 | } // namespace xml 123 | -------------------------------------------------------------------------------- /src/libxml/node_iterator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org) 3 | * 2009 Vaclav Slavik 4 | * All Rights Reserved 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name of the Author nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 23 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 24 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 27 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 30 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef _xmlwrapp_node_iterator_h_ 35 | #define _xmlwrapp_node_iterator_h_ 36 | 37 | // xmlwrapp includes 38 | #include "xmlwrapp/node.h" 39 | 40 | // libxml includes 41 | #include 42 | 43 | namespace xml 44 | { 45 | 46 | namespace impl 47 | { 48 | 49 | // helper to obtain the next node in "filtering" iterators (as used by 50 | // nodes_view and const_nodes_view) 51 | // 52 | // Note: This class is reference-counted; don't delete instance of it, use 53 | // dec_ref() and inc_ref(). Newly created instance has reference count 54 | // of 1. 55 | class iter_advance_functor 56 | { 57 | public: 58 | iter_advance_functor() = default; 59 | 60 | void inc_ref() 61 | { 62 | refcnt_++; 63 | } 64 | 65 | void dec_ref() 66 | { 67 | if ( --refcnt_ == 0 ) 68 | delete this; 69 | } 70 | 71 | virtual xmlNodePtr operator()(xmlNodePtr node) const = 0; 72 | 73 | protected: 74 | // use inc_ref(), dec_ref() instead of using the dtor explicitly 75 | virtual ~iter_advance_functor() = default; 76 | 77 | private: 78 | // no copy ctor or assignment 79 | iter_advance_functor(const iter_advance_functor& other) = delete; 80 | iter_advance_functor& operator=(const iter_advance_functor& other) = delete; 81 | 82 | private: 83 | int refcnt_{1}; 84 | }; 85 | 86 | // base iterator class 87 | class node_iterator 88 | { 89 | public: 90 | node_iterator() : fake_node_(0), node_(nullptr) {} 91 | 92 | node_iterator(node &parent) 93 | : fake_node_(0), 94 | node_(reinterpret_cast(parent.get_node_data())) 95 | { 96 | } 97 | 98 | node_iterator(xmlNodePtr xmlnode) : fake_node_(0), node_(xmlnode) {} 99 | node_iterator(const node_iterator& other) : fake_node_(0), node_(other.node_) {} 100 | node_iterator& operator=(const node_iterator& other) 101 | { node_ = other.node_; return *this;} 102 | 103 | node *get() const; 104 | xmlNodePtr get_raw_node() { return node_; } 105 | 106 | void advance() { node_ = node_->next; } 107 | void advance(iter_advance_functor& next) { node_ = next(node_); } 108 | 109 | private: 110 | mutable node fake_node_; 111 | xmlNodePtr node_; 112 | }; 113 | 114 | } // namespace impl 115 | 116 | } // namespace xml 117 | 118 | #endif // _xmlwrapp_node_iterator_h_ 119 | -------------------------------------------------------------------------------- /src/libxml/node_manip.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org) 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | /** 34 | @file 35 | 36 | This file contains the definition of the xml::node manipulation functions. 37 | */ 38 | 39 | #ifndef _xmlwrapp_node_manip_h_ 40 | #define _xmlwrapp_node_manip_h_ 41 | 42 | // libxml includes 43 | #include 44 | 45 | namespace xml 46 | { 47 | 48 | namespace impl 49 | { 50 | 51 | /** 52 | @internal 53 | 54 | Insert a node somewhere in the child list of a parent node. 55 | 56 | @param parent The parent who's child list will be inserted into. 57 | @param before Insert @a to_add before this node, or, if this node is 58 | 0 (null), insert at the end of the child list. 59 | @param to_add The node to be copied and then inserted into the child list. 60 | 61 | @return The new node that was inserted into the child list. 62 | */ 63 | xmlNodePtr node_insert(xmlNodePtr parent, xmlNodePtr before, xmlNodePtr to_add); 64 | 65 | /** 66 | @internal 67 | 68 | Replace a node with another one. The node being replaced will be 69 | freed from memory. 70 | 71 | @param old_node The old node to remove and free. 72 | @param new_node The new node to copy and insert where old node was. 73 | 74 | @return The new node that was crated from copying @a new_node and inserted 75 | into the child list where @a old_node was. 76 | */ 77 | xmlNodePtr node_replace(xmlNodePtr old_node, xmlNodePtr new_node); 78 | 79 | /** 80 | @internal 81 | 82 | Erase a node from the child list, and then free it from memory. 83 | 84 | @param to_erase The node to remove and free. 85 | 86 | @return The node that was after to_erase (may be 0 (null) if @a to_erase 87 | was the last node in the list) 88 | */ 89 | xmlNodePtr node_erase(xmlNodePtr to_erase); 90 | 91 | /** 92 | @internal 93 | 94 | Set namespace for this node and all its children not using any namespace. 95 | */ 96 | void node_set_ns_recursively(xmlNodePtr node, xmlNsPtr ns); 97 | 98 | } // namespace impl 99 | 100 | } // namespace xml 101 | 102 | #endif // _xmlwrapp_node_manip_h_ 103 | -------------------------------------------------------------------------------- /src/libxml/nodes_view.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 Vaclav Slavik 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | 34 | // xmlwrapp includes 35 | #include "xmlwrapp/nodes_view.h" 36 | 37 | // definition include 38 | #include "node_iterator.h" 39 | #include "node_manip.h" 40 | #include "utility.h" 41 | 42 | using namespace xml::impl; 43 | 44 | namespace xml 45 | { 46 | 47 | // ------------------------------------------------------------------------ 48 | // xml::const_nodes_view 49 | // ------------------------------------------------------------------------ 50 | 51 | const_nodes_view::const_nodes_view(const const_nodes_view& other) 52 | : data_begin_(other.data_begin_), 53 | advance_func_(other.advance_func_) 54 | { 55 | if ( advance_func_ ) 56 | advance_func_->inc_ref(); 57 | } 58 | 59 | 60 | const_nodes_view::const_nodes_view(const nodes_view& other) 61 | : data_begin_(other.data_begin_), 62 | advance_func_(other.advance_func_) 63 | { 64 | if ( advance_func_ ) 65 | advance_func_->inc_ref(); 66 | } 67 | 68 | 69 | const_nodes_view::~const_nodes_view() 70 | { 71 | if ( advance_func_ ) 72 | advance_func_->dec_ref(); 73 | } 74 | 75 | 76 | const_nodes_view& const_nodes_view::operator=(const const_nodes_view& other) 77 | { 78 | if ( advance_func_ ) 79 | advance_func_->dec_ref(); 80 | 81 | data_begin_ = other.data_begin_; 82 | advance_func_ = other.advance_func_; 83 | 84 | if ( advance_func_ ) 85 | advance_func_->inc_ref(); 86 | 87 | return *this; 88 | } 89 | 90 | 91 | const_nodes_view& const_nodes_view::operator=(const nodes_view& other) 92 | { 93 | if ( advance_func_ ) 94 | advance_func_->dec_ref(); 95 | 96 | data_begin_ = other.data_begin_; 97 | advance_func_ = other.advance_func_; 98 | 99 | if ( advance_func_ ) 100 | advance_func_->inc_ref(); 101 | 102 | return *this; 103 | } 104 | 105 | 106 | const_nodes_view::size_type const_nodes_view::size() const 107 | { 108 | using namespace std; 109 | return checked_size_t_cast(distance(begin(), end())); 110 | } 111 | 112 | 113 | // ------------------------------------------------------------------------ 114 | // xml::nodes_view 115 | // ------------------------------------------------------------------------ 116 | 117 | nodes_view::nodes_view(const nodes_view& other) 118 | : data_begin_(other.data_begin_), 119 | advance_func_(other.advance_func_) 120 | { 121 | if ( advance_func_ ) 122 | advance_func_->inc_ref(); 123 | } 124 | 125 | 126 | nodes_view::~nodes_view() 127 | { 128 | if ( advance_func_ ) 129 | advance_func_->dec_ref(); 130 | } 131 | 132 | 133 | nodes_view& nodes_view::operator=(const nodes_view& other) 134 | { 135 | if ( advance_func_ ) 136 | advance_func_->dec_ref(); 137 | 138 | data_begin_ = other.data_begin_; 139 | advance_func_ = other.advance_func_; 140 | 141 | if ( advance_func_ ) 142 | advance_func_->inc_ref(); 143 | 144 | return *this; 145 | } 146 | 147 | 148 | nodes_view::size_type nodes_view::size() const 149 | { 150 | using namespace std; 151 | return checked_size_t_cast(distance(begin(), end())); 152 | } 153 | 154 | 155 | nodes_view::iterator nodes_view::erase(const nodes_view::iterator& to_erase) 156 | { 157 | iterator next(to_erase); 158 | ++next; 159 | xml::impl::node_erase(static_cast(to_erase.get_raw_node())); 160 | return next; 161 | } 162 | 163 | 164 | nodes_view::iterator nodes_view::erase(nodes_view::iterator first, 165 | const nodes_view::iterator& last) 166 | { 167 | while (first != last) 168 | first = erase(first); 169 | return first; 170 | } 171 | 172 | } // namespace xml 173 | -------------------------------------------------------------------------------- /src/libxml/relaxng.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Vadim Zeitlin 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the relaxngation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | // xmlwrapp includes 34 | #include "xmlwrapp/relaxng.h" 35 | #include "xmlwrapp/document.h" 36 | #include "xmlwrapp/errors.h" 37 | 38 | #include "errors_impl.h" 39 | 40 | // libxml includes 41 | #include 42 | 43 | namespace xml 44 | { 45 | 46 | using namespace impl; 47 | 48 | // ------------------------------------------------------------------------ 49 | // xml::impl::relaxng_impl 50 | // ------------------------------------------------------------------------ 51 | 52 | namespace impl 53 | { 54 | 55 | struct relaxng_impl 56 | { 57 | relaxng_impl(xmlDocPtr xmldoc, error_handler& on_error) 58 | { 59 | impl::errors_collector err; 60 | 61 | xmlRelaxNGParserCtxtPtr ctxt = xmlRelaxNGNewDocParserCtxt(xmldoc); 62 | if ( !ctxt ) 63 | throw std::bad_alloc(); 64 | xmlRelaxNGSetParserErrors(ctxt, 65 | cb_messages_error, cb_messages_warning, 66 | &err); 67 | 68 | relaxng_ = xmlRelaxNGParse(ctxt); 69 | xmlRelaxNGFreeParserCtxt(ctxt); 70 | 71 | if ( !relaxng_ ) 72 | { 73 | err.replay(on_error); 74 | // if the handler didn't throw, do it ourselves -- it's the only 75 | // way to signal fatal errors from a ctor: 76 | throw exception(err); 77 | } 78 | } 79 | 80 | ~relaxng_impl() 81 | { 82 | if (relaxng_) 83 | xmlRelaxNGFree(relaxng_); 84 | } 85 | 86 | xmlRelaxNGPtr relaxng_{nullptr}; 87 | }; 88 | 89 | } // namespace impl 90 | 91 | 92 | // ------------------------------------------------------------------------ 93 | // xml::relaxng 94 | // ------------------------------------------------------------------------ 95 | 96 | relaxng::relaxng(const document& doc, error_handler& on_error) 97 | { 98 | // Note that, unlike xmlSchemaNewDocParserCtxt(), we don't need to make a 99 | // copy of the document here as xmlRelaxNGNewDocParserCtxt() already does 100 | // it internally. 101 | auto xmldoc = static_cast(doc.get_doc_data_read_only()); 102 | 103 | pimpl_.reset(new relaxng_impl(xmldoc, on_error)); 104 | } 105 | 106 | relaxng::~relaxng() = default; 107 | 108 | 109 | bool relaxng::validate(const document& doc, error_handler& on_error) const 110 | { 111 | auto xmldoc = static_cast(doc.get_doc_data_read_only()); 112 | 113 | xmlRelaxNGValidCtxtPtr ctxt = xmlRelaxNGNewValidCtxt(pimpl_->relaxng_); 114 | if ( !ctxt ) 115 | throw std::bad_alloc(); 116 | 117 | impl::errors_collector err; 118 | xmlRelaxNGSetValidErrors(ctxt, 119 | cb_messages_error, cb_messages_warning, 120 | &err); 121 | 122 | int ret = xmlRelaxNGValidateDoc(ctxt, xmldoc); 123 | 124 | xmlRelaxNGFreeValidCtxt(ctxt); 125 | 126 | if ( ret == -1 ) 127 | throw xml::exception("internal validation error"); 128 | 129 | err.replay(on_error); 130 | 131 | return ret == 0; 132 | } 133 | 134 | } // namespace xml 135 | -------------------------------------------------------------------------------- /src/libxml/schema.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Vaclav Slavik 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the schemaation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | // xmlwrapp includes 34 | #include "xmlwrapp/schema.h" 35 | #include "xmlwrapp/document.h" 36 | #include "xmlwrapp/errors.h" 37 | 38 | #include "errors_impl.h" 39 | 40 | // libxml includes 41 | #include 42 | 43 | namespace xml 44 | { 45 | 46 | using namespace impl; 47 | 48 | // ------------------------------------------------------------------------ 49 | // xml::impl::schema_impl 50 | // ------------------------------------------------------------------------ 51 | 52 | namespace impl 53 | { 54 | 55 | struct schema_impl 56 | { 57 | schema_impl(xmlDocPtr xmldoc, error_handler& on_error) 58 | { 59 | impl::errors_collector err; 60 | 61 | xmlSchemaParserCtxtPtr ctxt = xmlSchemaNewDocParserCtxt(xmldoc); 62 | if ( !ctxt ) 63 | throw std::bad_alloc(); 64 | xmlSchemaSetParserErrors(ctxt, 65 | cb_messages_error, cb_messages_warning, 66 | &err); 67 | 68 | schema_ = xmlSchemaParse(ctxt); 69 | xmlSchemaFreeParserCtxt(ctxt); 70 | 71 | if ( !schema_ ) 72 | { 73 | err.replay(on_error); 74 | // if the handler didn't throw, do it ourselves -- it's the only 75 | // way to signal fatal errors from a ctor: 76 | throw exception(err); 77 | } 78 | } 79 | 80 | ~schema_impl() 81 | { 82 | if (schema_) 83 | xmlSchemaFree(schema_); 84 | if (retainDoc_) 85 | xmlFreeDoc(retainDoc_); 86 | } 87 | 88 | xmlSchemaPtr schema_{nullptr}; 89 | xmlDocPtr retainDoc_{nullptr}; 90 | }; 91 | 92 | } // namespace impl 93 | 94 | 95 | // ------------------------------------------------------------------------ 96 | // xml::schema 97 | // ------------------------------------------------------------------------ 98 | 99 | schema::schema(const document& doc, error_handler& on_error) 100 | { 101 | // xmlSchemaNewDocParserCtxt() modifies the document during parsing, 102 | // so we have to make a private copy first 103 | document mydoc(doc); 104 | 105 | auto xmldoc = static_cast(mydoc.get_doc_data_read_only()); 106 | pimpl_.reset(new schema_impl(xmldoc, on_error)); 107 | 108 | // xmldoc is still used in the schema_, but it's not owned (and thus freed) 109 | // by it, we have to manage its lifetime outselves. Transfer the ownership 110 | // here and clear 'mydoc' of any data. 111 | // 112 | // Note that the document was already modified by libxml2 in the process of 113 | // parsing it, so it's not usable by the caller anymore. 114 | mydoc.release_doc_data(); 115 | pimpl_->retainDoc_ = xmldoc; 116 | } 117 | 118 | schema::~schema() = default; 119 | 120 | 121 | bool schema::validate(const document& doc, error_handler& on_error) const 122 | { 123 | auto xmldoc = static_cast(doc.get_doc_data_read_only()); 124 | 125 | xmlSchemaValidCtxtPtr ctxt = xmlSchemaNewValidCtxt(pimpl_->schema_); 126 | if ( !ctxt ) 127 | throw std::bad_alloc(); 128 | 129 | impl::errors_collector err; 130 | xmlSchemaSetValidErrors(ctxt, 131 | cb_messages_error, cb_messages_warning, 132 | &err); 133 | 134 | int ret = xmlSchemaValidateDoc(ctxt, xmldoc); 135 | 136 | xmlSchemaFreeValidCtxt(ctxt); 137 | 138 | if ( ret == -1 ) 139 | throw xml::exception("internal validation error"); 140 | 141 | err.replay(on_error); 142 | 143 | return ret == 0; 144 | } 145 | 146 | } // namespace xml 147 | -------------------------------------------------------------------------------- /src/libxml/utility.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org) 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | #include "utility.h" 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | // hack to pull in vsnprintf for MSVC 41 | #if defined(_MSC_VER) || (defined(__COMO__) && defined(__WIN32__)) 42 | #undef vsnprintf 43 | #define vsnprintf _vsnprintf 44 | #endif 45 | 46 | namespace xml 47 | { 48 | 49 | namespace impl 50 | { 51 | 52 | void printf2string(std::string& s, const char *message, va_list ap) 53 | { 54 | char buffer[512]; 55 | 56 | std::memset(buffer, 0, sizeof(buffer)); 57 | 58 | // XXX vsnprintf is non-standard 59 | if (vsnprintf(buffer, sizeof(buffer), message, ap) > 0) 60 | { 61 | std::string::size_type size = std::strlen(buffer); 62 | 63 | if ( buffer[size-1] == '\n' ) 64 | --size; 65 | s.assign(buffer, size); 66 | } 67 | } 68 | 69 | } // namespace impl 70 | 71 | } // namespace xml 72 | -------------------------------------------------------------------------------- /src/libxml/utility.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org) 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | #ifndef _xmlwrapp_utility_h_ 34 | #define _xmlwrapp_utility_h_ 35 | 36 | #include 37 | 38 | // standard includes 39 | #include 40 | #include 41 | #include 42 | 43 | // libxml2 includes 44 | #include 45 | 46 | namespace xml 47 | { 48 | 49 | namespace impl 50 | { 51 | 52 | // Helper for holding libxml objects with guaranteed freeing 53 | template 54 | class xml_scoped_ptr 55 | { 56 | public: 57 | explicit xml_scoped_ptr(TPtr ptr) : ptr_(ptr) {} 58 | 59 | ~xml_scoped_ptr() 60 | { 61 | if (ptr_) 62 | FreeFunc(ptr_); 63 | } 64 | 65 | TPtr operator->() const { return ptr_; } 66 | TPtr get() const { return ptr_; } 67 | operator TPtr() const { return ptr_; } 68 | 69 | private: 70 | TPtr ptr_; 71 | }; 72 | 73 | // exception safe wrapper around xmlChar*s that are returned from some 74 | // of the libxml functions that the user must free. 75 | class xmlchar_helper 76 | { 77 | public: 78 | xmlchar_helper(xmlChar *ptr) : ptr_(ptr) {} 79 | 80 | ~xmlchar_helper() 81 | { if (ptr_) xmlFree(ptr_); } 82 | 83 | const char* get() const 84 | { return reinterpret_cast(ptr_); } 85 | 86 | private: 87 | xmlChar *ptr_; 88 | }; 89 | 90 | inline const xmlChar* xml_string(const std::string& s) 91 | { 92 | return reinterpret_cast(s.c_str()); 93 | } 94 | 95 | // Formats given message with arguments into a std::string 96 | void printf2string(std::string& s, const char *message, va_list ap); 97 | 98 | // Sun CC uses ancient C++ standard library that doesn't have standard 99 | // std::distance(). Work around it here 100 | #if defined(__SUNPRO_CC) && !defined(_STLPORT_VERSION) 101 | template 102 | inline size_t distance(T a, const T&b) 103 | { 104 | size_t n = 0; 105 | for ( ; a != b; ++a ) 106 | ++n; 107 | return n; 108 | } 109 | #endif // defined(__SUNPRO_CC) && !defined(_STLPORT_VERSION) 110 | 111 | // Cast size_t to int safely, i.e. throw an exception in case of an overflow. 112 | inline int checked_int_cast(std::size_t len) 113 | { 114 | if ( len > INT_MAX ) 115 | throw std::invalid_argument("data too long"); 116 | 117 | return static_cast(len); 118 | } 119 | 120 | // Cast int to size_t safely, checking that it's non-negative (we assume that 121 | // size_t is always big enough to contain INT_MAX, which is true for all 122 | // currently existing architectures). 123 | inline std::size_t checked_size_t_cast(int len) 124 | { 125 | if ( len < 0 ) 126 | throw std::runtime_error("length value unexpectedly negative"); 127 | 128 | return static_cast(len); 129 | } 130 | 131 | } // namespace impl 132 | 133 | } // namespace xml 134 | 135 | 136 | #endif // _xmlwrapp_utility_h_ 137 | -------------------------------------------------------------------------------- /src/libxslt/init.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org) 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | /** 34 | @file 35 | 36 | This file contains the implementation of the xslt::init class. 37 | */ 38 | 39 | #include "xsltwrapp/init.h" 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | extern "C" 48 | { 49 | 50 | static void xslt_error(void *, const char*, ...) 51 | { 52 | // don't do anything; we install context-specific error handler to 53 | // catch errors while applying a stylesheet 54 | } 55 | 56 | } // extern "C" 57 | 58 | 59 | int xslt::init::ms_counter = 0; 60 | 61 | 62 | xslt::init::init() 63 | { 64 | if ( ms_counter++ == 0 ) 65 | init_library(); 66 | } 67 | 68 | 69 | xslt::init::~init() 70 | { 71 | if ( --ms_counter == 0 ) 72 | shutdown_library(); 73 | } 74 | 75 | 76 | void xslt::init::init_library() 77 | { 78 | // xsltInit() was added after 1.1.15 release, so don't use it with the 79 | // ancient libxslt version (which is the only one we have under Solaris). 80 | #if LIBXSLT_VERSION > 10115 81 | xsltInit(); 82 | #endif 83 | 84 | // set some defautls 85 | process_xincludes(true); 86 | 87 | // keep libxslt silent; we install context-specific error handler to 88 | // catch errors while applying a stylesheet 89 | xsltSetGenericErrorFunc(nullptr, xslt_error); 90 | xsltSetGenericDebugFunc(nullptr, xslt_error); 91 | 92 | // load EXSLT 93 | exsltRegisterAll(); 94 | } 95 | 96 | 97 | void xslt::init::shutdown_library() 98 | { 99 | xsltCleanupGlobals(); 100 | } 101 | 102 | 103 | void xslt::init::process_xincludes(bool flag) 104 | { 105 | xsltSetXIncludeDefault(flag ? 1 : 0); 106 | } 107 | -------------------------------------------------------------------------------- /src/libxslt/result.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 Vadim Zeitlin (vz-xmlwrapp@zeitlins.org) 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | /** 34 | @file 35 | 36 | This file contains the declaration of the xslt::result class. 37 | */ 38 | 39 | #ifndef _xsltwrapp_result_h_ 40 | #define _xsltwrapp_result_h_ 41 | 42 | // standard includes 43 | #include 44 | 45 | // forward declarations 46 | typedef struct _xmlDoc *xmlDocPtr; 47 | 48 | namespace xslt 49 | { 50 | 51 | namespace impl 52 | { 53 | 54 | /** 55 | @internal 56 | 57 | The xslt::result class is used as a callback by xml::document to allow 58 | special treatment of XML documents which were created by XSLT. 59 | 60 | This class is only meant to be used internally by the library and is 61 | necessary to avoid the dependency of xml::document, which is part of 62 | libxmlwrapp, on libxslt which should be only a dependency of libxsltwrapp 63 | as this precludes calling the XSLT functions which must be used with such 64 | "result" documents directly from xml::document code. 65 | */ 66 | class result 67 | { 68 | public: 69 | /** 70 | Save the contents of the given XML document in the provided string. 71 | 72 | @param s The string to place the XML text data. 73 | */ 74 | virtual void save_to_string(std::string &s) const = 0; 75 | 76 | /** 77 | Save the contents of the given XML document in the provided filename. 78 | 79 | @param filename 80 | The name of the file to place the XML text data into. 81 | @param compression_level 82 | 0 is no compression, 1-9 allowed, where 1 is for better speed, 83 | and 9 is for smaller size 84 | @return True if the data was saved successfully, false otherwise. 85 | */ 86 | virtual bool save_to_file(const char *filename, 87 | int compression_level) const = 0; 88 | 89 | /// Trivial but virtual base class destructor. 90 | virtual ~result() = default; 91 | }; 92 | 93 | } // end impl namespace 94 | 95 | } // end xslt namespace 96 | 97 | #endif // _xsltwrapp_result_h_ 98 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | TESTS = test 3 | 4 | AM_CPPFLAGS = -I$(top_srcdir)/include 5 | LIBS = $(top_builddir)/src/libxmlwrapp.la 6 | 7 | noinst_PROGRAMS = test 8 | 9 | test_SOURCES = \ 10 | test.h \ 11 | catch.hpp \ 12 | test_main.cxx \ 13 | attributes/test_attributes.cxx \ 14 | document/test_document.cxx \ 15 | event/test_event.cxx \ 16 | node/test_node.cxx \ 17 | tree/test_tree.cxx \ 18 | relaxng/test_relaxng.cxx \ 19 | schema/test_schema.cxx \ 20 | xpath/test_xpath.cxx 21 | 22 | if WITH_XSLT 23 | LIBS += $(top_builddir)/src/libxsltwrapp.la 24 | test_SOURCES += xslt/test_xslt.cxx 25 | endif 26 | 27 | EXTRA_DIST = \ 28 | $(srcdir)/*/data/*.out \ 29 | $(srcdir)/*/data/*.rnc \ 30 | $(srcdir)/*/data/*.rng \ 31 | $(srcdir)/*/data/*.xml \ 32 | $(srcdir)/*/data/*.xsl \ 33 | $(srcdir)/*/data/*.xsd \ 34 | $(srcdir)/*/data/*.dtd \ 35 | $(srcdir)/*/data/output 36 | -------------------------------------------------------------------------------- /tests/attributes/data/01a.out: -------------------------------------------------------------------------------- 1 | a=a 2 | b=b 3 | c=c 4 | d=d 5 | -------------------------------------------------------------------------------- /tests/attributes/data/01a.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/01b.out: -------------------------------------------------------------------------------- 1 | a=a 2 | a=ta 3 | b=b 4 | b=tb 5 | -------------------------------------------------------------------------------- /tests/attributes/data/01b.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/01c.out: -------------------------------------------------------------------------------- 1 | first=this & that 2 | second=who is on first? 3 | -------------------------------------------------------------------------------- /tests/attributes/data/01c.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/02.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/attributes/data/02.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/03.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/04.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/04a.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/attributes/data/04b.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/attributes/data/04c.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/attributes/data/04d.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/attributes/data/06a.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/06b.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/07a.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/07b.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/07c.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/07d.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/08.out: -------------------------------------------------------------------------------- 1 | first_attr=1 2 | second_attr=2 3 | thrid_attr=3 4 | -------------------------------------------------------------------------------- /tests/attributes/data/08.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/09.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/attributes/data/09.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/attributes/data/10.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/attributes/data/10.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | See? 4 | -------------------------------------------------------------------------------- /tests/document/data/01.out: -------------------------------------------------------------------------------- 1 | type_pi 2 | type_comment 3 | type_element 4 | type_comment 5 | -------------------------------------------------------------------------------- /tests/document/data/01.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/document/data/02.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/document/data/03.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/document/data/04.out: -------------------------------------------------------------------------------- 1 | 2 | pcdata 3 | -------------------------------------------------------------------------------- /tests/document/data/08.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | pcdata 5 | -------------------------------------------------------------------------------- /tests/document/data/09.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/document/data/10.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/document/data/11.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/document/data/12.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/document/data/13a.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/document/data/13a.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/document/data/13b.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/document/data/13b.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/document/data/14.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/document/data/14.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/document/data/14inc.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/document/data/15.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/document/data/17.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/document/data/19.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /tests/document/data/21.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /tests/event/data/01.out: -------------------------------------------------------------------------------- 1 | -- CTOR: 2 | -- START_ELEMENT: root 3 | -- TEXT: 4 | 5 | -- COMMENT: just under root 6 | -- TEXT: 7 | 8 | -- START_ELEMENT: one 9 | -- TEXT: 10 | 11 | -- START_ELEMENT: one_dot_one 12 | -- END_ELEMENT: one_dot_one 13 | -- TEXT: 14 | 15 | -- END_ELEMENT: one 16 | -- TEXT: 17 | 18 | 19 | -- START_ELEMENT: two 20 | -- TEXT: 21 | 22 | -- START_ELEMENT: two_dot_one 23 | -- TEXT: 24 | 25 | -- START_ELEMENT: two_dot_two 26 | -- CDATA: inside two_dot_two 27 | -- END_ELEMENT: two_dot_two 28 | -- TEXT: 29 | 30 | -- END_ELEMENT: two_dot_one 31 | -- TEXT: 32 | 33 | -- END_ELEMENT: two 34 | -- TEXT: 35 | 36 | -- PI: TARGET=someapp DATA=just above /root 37 | -- TEXT: 38 | 39 | -- END_ELEMENT: root 40 | -- DTOR: 41 | -------------------------------------------------------------------------------- /tests/event/data/01.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/node/data/01.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | one 4 | two 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/node/data/02.xml: -------------------------------------------------------------------------------- 1 | PeterCOIsaacCAAlbertAZ 2 | -------------------------------------------------------------------------------- /tests/node/data/02_after_move.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Isaac 5 | CA 6 | 7 | 8 | 9 | Peter 10 | CO 11 | 12 | 13 | 14 | Albert 15 | AZ 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/node/data/02a.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | Peter 4 | CO 5 | 6 | -------------------------------------------------------------------------------- /tests/node/data/02c.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | Peter 4 | CO 5 | 6 | 7 | 8 | Isaac 9 | CA 10 | 11 | 12 | 13 | Albert 14 | AZ 15 | 16 | -------------------------------------------------------------------------------- /tests/node/data/02g.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | Peter 4 | CO 5 | 6 | 7 | 8 | Isaac 9 | CA 10 | 11 | 12 | 13 | 14 | 15 | Albert 16 | AZ 17 | 18 | -------------------------------------------------------------------------------- /tests/node/data/03.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/node/data/03a.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/node/data/03b.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/node/data/04.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/node/data/04a.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/node/data/04b.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/node/data/04c.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/node/data/05.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/node/data/05a.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/node/data/05b.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/node/data/05c.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/node/data/05d.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/node/data/06a.out: -------------------------------------------------------------------------------- 1 | type_element 2 | type_element 3 | type_element 4 | type_text 5 | -------------------------------------------------------------------------------- /tests/node/data/06a.xml: -------------------------------------------------------------------------------- 1 | Title 2 | -------------------------------------------------------------------------------- /tests/node/data/06b.out: -------------------------------------------------------------------------------- 1 | type_element 2 | type_comment 3 | type_text 4 | type_pi 5 | type_text 6 | type_element 7 | type_element 8 | type_cdata 9 | type_text 10 | -------------------------------------------------------------------------------- /tests/node/data/06b.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | <![CDATA[text]]> 4 | 5 | -------------------------------------------------------------------------------- /tests/node/data/06c.out: -------------------------------------------------------------------------------- 1 | type_element 2 | type_entity_ref 3 | type_dtd_entity 4 | type_text 5 | -------------------------------------------------------------------------------- /tests/node/data/06c.xml: -------------------------------------------------------------------------------- 1 | 3 | ]> 4 | &myname; 5 | -------------------------------------------------------------------------------- /tests/node/data/07a.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/node/data/07a.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/node/data/07b.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/node/data/07b.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/node/data/08a.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/node/data/08a.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/node/data/09.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/node/data/10.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/node/data/11.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/node/data/14.out: -------------------------------------------------------------------------------- 1 | 2 | some text 3 | -------------------------------------------------------------------------------- /tests/node/data/copy_ns.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/node/data/empty.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/node/data/namespace.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/node/data/namespace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/node/data/special_chars.xml: -------------------------------------------------------------------------------- 1 | 2 | Marlow & Sons 3 | -------------------------------------------------------------------------------- /tests/relaxng/data/invalid.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/relaxng/data/nonvalid.xml: -------------------------------------------------------------------------------- 1 | 2 | YYY 3 | ZZZ 4 | 5 | -------------------------------------------------------------------------------- /tests/relaxng/data/schema.rnc: -------------------------------------------------------------------------------- 1 | # If you're reading this comment in the XML schema.rng file, notice that it was 2 | # automatically copied there by trang conversion tool from schema.rnc, using 3 | # the compact RelaxNG syntax not currently directly supported by libxml2 (and 4 | # hence neither xmlwrapp), but which is far more convenient than the XML syntax 5 | # and so is used as the real source of this schema. 6 | # 7 | # Run "trang schema.rnc schema.rng" to (re)generate the XML schema from it. 8 | start = element AAA 9 | { 10 | element BBB { string }, 11 | element CCC { string } 12 | } 13 | -------------------------------------------------------------------------------- /tests/relaxng/data/schema.rng: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/relaxng/data/valid.xml: -------------------------------------------------------------------------------- 1 | 2 | ZZZ 3 | YYY 4 | 5 | -------------------------------------------------------------------------------- /tests/relaxng/test_relaxng.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Vadim Zeitlin 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | #include "../test.h" 34 | 35 | TEST_CASE_METHOD( SrcdirConfig, "relaxng/load_non_relaxng_file", "[relaxng]" ) 36 | { 37 | xml::document sch_doc = 38 | xml::tree_parser(test_file_path("relaxng/data/valid.xml").c_str()).get_document(); 39 | 40 | CHECK_THROWS_AS 41 | ( 42 | xml::relaxng(sch_doc), 43 | xml::exception 44 | ); 45 | 46 | xml::error_messages log; 47 | // throw even when collecting errors into log 48 | CHECK_THROWS_AS 49 | ( 50 | xml::relaxng(sch_doc, log), 51 | xml::exception 52 | ); 53 | CHECK( log.has_errors() ); 54 | } 55 | 56 | 57 | TEST_CASE_METHOD( SrcdirConfig, "relaxng/validate_ok", "[relaxng]" ) 58 | { 59 | xml::document sch_doc = 60 | xml::tree_parser(test_file_path("relaxng/data/schema.rng").c_str()).get_document(); 61 | xml::relaxng sch(sch_doc); 62 | 63 | xml::document doc = 64 | xml::tree_parser(test_file_path("relaxng/data/valid.xml").c_str()).get_document(); 65 | 66 | CHECK( sch.validate(doc) ); 67 | 68 | // And the same with logging: 69 | xml::error_messages log; 70 | CHECK( sch.validate(doc) ); 71 | CHECK( !log.has_errors() ); 72 | CHECK( !log.has_warnings() ); 73 | } 74 | 75 | 76 | TEST_CASE_METHOD( SrcdirConfig, "relaxng/validate_invalid", "[relaxng]" ) 77 | { 78 | xml::document sch_doc = 79 | xml::tree_parser(test_file_path("relaxng/data/schema.rng").c_str()).get_document(); 80 | xml::relaxng sch(sch_doc); 81 | 82 | xml::document doc = 83 | xml::tree_parser(test_file_path("relaxng/data/invalid.xml").c_str()).get_document(); 84 | 85 | CHECK_THROWS_AS 86 | ( 87 | sch.validate(doc), 88 | xml::exception 89 | ); 90 | 91 | // And the same with logging: 92 | xml::error_messages log; 93 | CHECK( !sch.validate(doc, log) ); 94 | CHECK( log.has_errors() ); 95 | } 96 | 97 | 98 | TEST_CASE_METHOD( SrcdirConfig, "relaxng/validate_nonvalid", "[relaxng]" ) 99 | { 100 | xml::document sch_doc = 101 | xml::tree_parser(test_file_path("relaxng/data/schema.rng").c_str()).get_document(); 102 | xml::relaxng sch(sch_doc); 103 | 104 | xml::document doc = 105 | xml::tree_parser(test_file_path("relaxng/data/nonvalid.xml").c_str()).get_document(); 106 | 107 | CHECK_THROWS_AS 108 | ( 109 | sch.validate(doc), 110 | xml::exception 111 | ); 112 | 113 | // And the same with logging: 114 | xml::error_messages log; 115 | CHECK( !sch.validate(doc, log) ); 116 | CHECK( log.has_errors() ); 117 | 118 | // The error message is "Did not expect element CCC there" because it's not 119 | // supposed to occur before "BBB". 120 | CHECK( log.print().find("CCC") != std::string::npos ); 121 | } 122 | -------------------------------------------------------------------------------- /tests/schema/data/invalid.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/schema/data/schema.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/schema/data/valid.xml: -------------------------------------------------------------------------------- 1 | 2 | ZZZ 3 | YYY 4 | 5 | -------------------------------------------------------------------------------- /tests/schema/test_schema.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Vaclav Slavik (vslavik@gmail.com) 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | #include "../test.h" 34 | 35 | TEST_CASE_METHOD( SrcdirConfig, "schema/load_non_schema_file", "[schema]" ) 36 | { 37 | xml::document sch_doc = 38 | xml::tree_parser(test_file_path("schema/data/valid.xml").c_str()).get_document(); 39 | 40 | CHECK_THROWS_AS 41 | ( 42 | xml::schema(sch_doc), 43 | xml::exception 44 | ); 45 | 46 | xml::error_messages log; 47 | // throw even when collecting errors into log 48 | CHECK_THROWS_AS 49 | ( 50 | xml::schema(sch_doc, log), 51 | xml::exception 52 | ); 53 | CHECK( log.has_errors() ); 54 | } 55 | 56 | 57 | TEST_CASE_METHOD( SrcdirConfig, "schema/validate_ok", "[schema]" ) 58 | { 59 | xml::document sch_doc = 60 | xml::tree_parser(test_file_path("schema/data/schema.xsd").c_str()).get_document(); 61 | xml::schema sch(sch_doc); 62 | 63 | xml::document doc = 64 | xml::tree_parser(test_file_path("schema/data/valid.xml").c_str()).get_document(); 65 | 66 | CHECK( sch.validate(doc) ); 67 | 68 | // And the same with logging: 69 | xml::error_messages log; 70 | CHECK( sch.validate(doc) ); 71 | CHECK( !log.has_errors() ); 72 | CHECK( !log.has_warnings() ); 73 | } 74 | 75 | 76 | TEST_CASE_METHOD( SrcdirConfig, "schema/validate_fail", "[schema]" ) 77 | { 78 | xml::document sch_doc = 79 | xml::tree_parser(test_file_path("schema/data/schema.xsd").c_str()).get_document(); 80 | xml::schema sch(sch_doc); 81 | 82 | xml::document doc = 83 | xml::tree_parser(test_file_path("schema/data/invalid.xml").c_str()).get_document(); 84 | 85 | CHECK_THROWS_AS 86 | ( 87 | sch.validate(doc), 88 | xml::exception 89 | ); 90 | 91 | // And the same with logging: 92 | xml::error_messages log; 93 | CHECK( !sch.validate(doc, log) ); 94 | CHECK( log.has_errors() ); 95 | } 96 | -------------------------------------------------------------------------------- /tests/test_main.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 Vaclav Slavik (vslavik@gmail.com) 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | #define CATCH_CONFIG_MAIN 34 | #include "test.h" 35 | 36 | #include 37 | 38 | std::string SrcdirConfig::srcdir; 39 | 40 | SrcdirConfig::SrcdirConfig() 41 | { 42 | if (srcdir.empty()) { 43 | const char *s = std::getenv("srcdir"); 44 | if ( s ) 45 | srcdir = s; 46 | else 47 | srcdir = "."; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tests/tree/data/bad.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/tree/data/good.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/tree/data/output: -------------------------------------------------------------------------------- 1 | root 2 | a 3 | b 4 | c 5 | d 6 | e 7 | f 8 | g 9 | -------------------------------------------------------------------------------- /tests/xpath/data/01.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/xpath/data/02.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/xpath/test_xpath.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Jonas Weber 3 | * All Rights Reserved 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 3. Neither the name of the Author nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 23 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | #include "../test.h" 34 | 35 | #include 36 | 37 | 38 | TEST_CASE_METHOD( SrcdirConfig, "xpath/create_context", "[xpath]" ) 39 | { 40 | xml::tree_parser parser(test_file_path("xpath/data/01.xml").c_str()); 41 | xml::xpath_context ctxt(parser.get_document()); 42 | } 43 | 44 | TEST_CASE_METHOD( SrcdirConfig, "xpath/evaluate", "[xpath]" ) 45 | { 46 | xml::tree_parser parser(test_file_path("xpath/data/01.xml").c_str()); 47 | xml::xpath_context ctxt(parser.get_document()); 48 | xml::const_nodes_view ns = ctxt.evaluate("//child"); 49 | 50 | CHECK( !ns.empty() ); 51 | } 52 | 53 | TEST_CASE_METHOD( SrcdirConfig, "xpath/evaluate_with_ns", "[xpath]" ) 54 | { 55 | xml::tree_parser parser(test_file_path("xpath/data/02.xml").c_str()); 56 | xml::xpath_context ctxt(parser.get_document()); 57 | 58 | xml::const_nodes_view ns1 = ctxt.evaluate("//child"); 59 | CHECK( ns1.empty() ); 60 | 61 | ctxt.register_namespace("p", "href"); 62 | xml::const_nodes_view ns2 = ctxt.evaluate("//p:child"); 63 | CHECK( !ns2.empty() ); 64 | CHECK( std::distance(ns2.begin(), ns2.end()) == 3 ); 65 | } 66 | 67 | TEST_CASE_METHOD( SrcdirConfig, "xpath/node_set_iterators", "[xpath]" ) 68 | { 69 | xml::tree_parser parser(test_file_path("xpath/data/02.xml").c_str()); 70 | xml::xpath_context ctxt(parser.get_document()); 71 | ctxt.register_namespace("p", "href"); 72 | xml::const_nodes_view ns = ctxt.evaluate("//p:child"); 73 | 74 | CHECK( ns.begin() == ns.begin() ); 75 | REQUIRE( !ns.empty() ); 76 | CHECK( ns.begin() != ns.end() ); 77 | 78 | xml::const_nodes_view::iterator it = ns.begin(); 79 | CHECK( it++ == ns.begin() ); 80 | CHECK( it != ns.begin() ); 81 | it = ns.begin(); 82 | CHECK( ++it != ns.begin() ); 83 | 84 | 85 | for (auto const& n : ns) 86 | { 87 | CHECK( n.get_name() ); 88 | } 89 | } 90 | 91 | TEST_CASE_METHOD( SrcdirConfig, "xpath/node_set_contains", "[xpath]" ) 92 | { 93 | xml::tree_parser parser(test_file_path("xpath/data/02.xml").c_str()); 94 | xml::xpath_context ctxt(parser.get_document()); 95 | 96 | ctxt.register_namespace("p", "href"); 97 | 98 | xml::const_nodes_view ns = ctxt.evaluate("//p:child"); 99 | CHECK( std::distance(ns.begin(), ns.end()) == 3 ); 100 | } 101 | 102 | TEST_CASE_METHOD( SrcdirConfig, "xpath/illegal_xpath", "[xpath]" ) 103 | { 104 | xml::tree_parser parser(test_file_path("xpath/data/02.xml").c_str()); 105 | xml::xpath_context ctxt(parser.get_document()); 106 | 107 | xml::const_nodes_view ns = ctxt.evaluate("ILLEGAL XPATH-QUERY", xml::ignore_errors); 108 | CHECK( ns.begin() == ns.end() ); 109 | 110 | CHECK_THROWS_AS 111 | ( 112 | ctxt.evaluate("ANOTHER ILLEGAL QUERY"), 113 | xml::exception 114 | ); 115 | } 116 | -------------------------------------------------------------------------------- /tests/xslt/data/01a.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/xslt/data/01b.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /tests/xslt/data/01c.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/xslt/data/02a.out: -------------------------------------------------------------------------------- 1 |

root

2 |

child

3 |

child

4 | 5 | -------------------------------------------------------------------------------- /tests/xslt/data/02a.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

root

5 |

child

6 |
7 | -------------------------------------------------------------------------------- /tests/xslt/data/03a.out: -------------------------------------------------------------------------------- 1 | foo == bar

root

2 |

child

3 |

child

4 | 5 | -------------------------------------------------------------------------------- /tests/xslt/data/03a.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | foo == 5 |

root

6 |

child

7 |
8 | -------------------------------------------------------------------------------- /tests/xslt/data/input.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/xslt/data/with_errors.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 42 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/xslt/test_xslt.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org) 3 | * Copyright (C) 2009 Vaclav Slavik (vslavik@gmail.com) 4 | * All Rights Reserved 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in 14 | * the documentation and/or other materials provided with the 15 | * distribution. 16 | * 3. Neither the name of the Author nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' 21 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 23 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR 24 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 27 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 30 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | */ 33 | 34 | #include "../test.h" 35 | 36 | #include 37 | 38 | /* 39 | * Test stylesheet creation 40 | */ 41 | 42 | TEST_CASE_METHOD( SrcdirConfig, "xslt/creation_fail1", "[xslt]" ) 43 | { 44 | CHECK_THROWS_AS 45 | ( 46 | xslt::stylesheet(test_file_path("xslt/data/01a.xsl").c_str()), 47 | xml::exception 48 | ); 49 | } 50 | 51 | TEST_CASE_METHOD( SrcdirConfig, "xslt/creation_ok", "[xslt]" ) 52 | { 53 | xslt::stylesheet style1(test_file_path("xslt/data/01b.xsl").c_str()); 54 | } 55 | 56 | TEST_CASE_METHOD( SrcdirConfig, "xslt/creation_fail2", "[xslt]" ) 57 | { 58 | CHECK_THROWS_AS 59 | ( 60 | xslt::stylesheet(test_file_path("xslt/data/01c.xsl").c_str()), 61 | xml::exception 62 | ); 63 | } 64 | 65 | 66 | /* 67 | * Test the first form of apply() 68 | */ 69 | 70 | TEST_CASE_METHOD( SrcdirConfig, "xslt/apply1", "[xslt]" ) 71 | { 72 | xslt::stylesheet style(test_file_path("xslt/data/02a.xsl").c_str()); 73 | xml::tree_parser parser(test_file_path("xslt/data/input.xml").c_str()); 74 | 75 | xml::document result; 76 | xml::error_messages errors; 77 | CHECK( style.apply(parser.get_document(), result, errors) ); 78 | 79 | CHECK( is_same_as_file(result, "xslt/data/02a.out") ); 80 | } 81 | 82 | 83 | /* 84 | * Test the third form of apply 85 | */ 86 | 87 | TEST_CASE_METHOD( SrcdirConfig, "xslt/apply3", "[xslt]" ) 88 | { 89 | xslt::stylesheet style(test_file_path("xslt/data/02a.xsl").c_str()); 90 | xml::tree_parser parser(test_file_path("xslt/data/input.xml").c_str()); 91 | 92 | xml::document& result = style.apply(parser.get_document()); 93 | CHECK( is_same_as_file(result, "xslt/data/02a.out") ); 94 | } 95 | 96 | 97 | /* 98 | * Test the second form of apply 99 | */ 100 | 101 | TEST_CASE_METHOD( SrcdirConfig, "xslt/apply2", "[xslt]" ) 102 | { 103 | xslt::stylesheet style(test_file_path("xslt/data/03a.xsl").c_str()); 104 | xml::tree_parser parser(test_file_path("xslt/data/input.xml").c_str()); 105 | 106 | xslt::stylesheet::param_type params; 107 | params["foo"] = "'bar'"; 108 | 109 | xml::document result; 110 | xml::error_messages errors; 111 | CHECK( style.apply(parser.get_document(), result, params, errors) ); 112 | CHECK( is_same_as_file(result, "xslt/data/03a.out") ); 113 | } 114 | 115 | 116 | /* 117 | * Test the fourth form of apply 118 | */ 119 | 120 | TEST_CASE_METHOD( SrcdirConfig, "xslt/apply4", "[xslt]" ) 121 | { 122 | xslt::stylesheet style(test_file_path("xslt/data/03a.xsl").c_str()); 123 | xml::tree_parser parser(test_file_path("xslt/data/input.xml").c_str()); 124 | 125 | xslt::stylesheet::param_type params; 126 | params["foo"] = "'bar'"; 127 | 128 | xml::document& result = style.apply(parser.get_document(), params); 129 | CHECK( is_same_as_file(result, "xslt/data/03a.out") ); 130 | } 131 | 132 | 133 | /* 134 | * Tests libxslt errors reporting 135 | */ 136 | 137 | TEST_CASE_METHOD( SrcdirConfig, "xslt/xsl_with_errors", "[xslt]" ) 138 | { 139 | xslt::stylesheet style(test_file_path("xslt/data/with_errors.xsl").c_str()); 140 | xml::tree_parser parser(test_file_path("xslt/data/input.xml").c_str()); 141 | 142 | xml::document result; 143 | xml::error_messages errors; 144 | CHECK( !style.apply(parser.get_document(), result, errors) ); 145 | } 146 | 147 | TEST_CASE_METHOD( SrcdirConfig, "xslt/xsl_with_errors_throw", "[xslt]" ) 148 | { 149 | xslt::stylesheet style(test_file_path("xslt/data/with_errors.xsl").c_str()); 150 | xml::tree_parser parser(test_file_path("xslt/data/input.xml").c_str()); 151 | 152 | CHECK_THROWS_AS 153 | ( 154 | style.apply(parser.get_document()), 155 | xml::exception 156 | ); 157 | } 158 | -------------------------------------------------------------------------------- /xmlwrapp-config.in: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | usage() 9 | { 10 | cat <