├── tests ├── node │ └── data │ │ ├── empty.xml │ │ ├── 04c.out │ │ ├── 05b.out │ │ ├── 05d.out │ │ ├── 14.out │ │ ├── 06a.xml │ │ ├── 10.out │ │ ├── 11.out │ │ ├── 09.out │ │ ├── 05.xml │ │ ├── special_chars.xml │ │ ├── 03b.out │ │ ├── 04b.out │ │ ├── 06a.out │ │ ├── 03a.out │ │ ├── 04.xml │ │ ├── 06c.out │ │ ├── 02a.out │ │ ├── 03.xml │ │ ├── 06c.xml │ │ ├── namespace.xml │ │ ├── 06b.xml │ │ ├── namespace.out │ │ ├── 04a.out │ │ ├── 08a.xml │ │ ├── 01.out │ │ ├── 05a.out │ │ ├── 05c.out │ │ ├── 08a.out │ │ ├── 02.xml │ │ ├── 06b.out │ │ ├── 07a.xml │ │ ├── 07a.out │ │ ├── 07b.xml │ │ ├── 07b.out │ │ ├── copy_ns.out │ │ ├── 02c.out │ │ ├── 02g.out │ │ └── 02_after_move.out ├── attributes │ └── data │ │ ├── 06a.xml │ │ ├── 07a.xml │ │ ├── 02.xml │ │ ├── 07b.xml │ │ ├── 06b.xml │ │ ├── 07c.xml │ │ ├── 01a.out │ │ ├── 01b.out │ │ ├── 01a.xml │ │ ├── 03.xml │ │ ├── 07d.xml │ │ ├── 02.out │ │ ├── 01c.out │ │ ├── 08.out │ │ ├── 08.xml │ │ ├── 09.xml │ │ ├── 01c.xml │ │ ├── 04.xml │ │ ├── 10.dtd │ │ ├── 04a.out │ │ ├── 04b.out │ │ ├── 04c.out │ │ ├── 04d.out │ │ ├── 01b.xml │ │ ├── 10.xml │ │ └── 09.dtd ├── document │ └── data │ │ ├── 13a.xml │ │ ├── 02.out │ │ ├── 03.out │ │ ├── 09.xml │ │ ├── 10.out │ │ ├── 04.out │ │ ├── 11.xml │ │ ├── 12.out │ │ ├── 13a.out │ │ ├── 13b.out │ │ ├── 13b.xml │ │ ├── 14inc.xml │ │ ├── 01.out │ │ ├── 15.out │ │ ├── 21.out │ │ ├── 19.out │ │ ├── 08.out │ │ ├── 01.xml │ │ ├── 17.out │ │ ├── 14.xml │ │ └── 14.out ├── tree │ └── data │ │ ├── bad.xml │ │ ├── good.xml │ │ └── output ├── xslt │ └── data │ │ ├── 01a.xsl │ │ ├── input.xml │ │ ├── 02a.out │ │ ├── 03a.out │ │ ├── 01b.xsl │ │ ├── 01c.xsl │ │ ├── 02a.xsl │ │ ├── 03a.xsl │ │ └── with_errors.xsl ├── relaxng │ ├── data │ │ ├── invalid.xml │ │ ├── nonvalid.xml │ │ ├── valid.xml │ │ ├── schema.rnc │ │ └── schema.rng │ └── test_relaxng.cxx ├── schema │ ├── data │ │ ├── invalid.xml │ │ ├── valid.xml │ │ └── schema.xsd │ └── test_schema.cxx ├── xpath │ ├── data │ │ ├── 01.xml │ │ └── 02.xml │ └── test_xpath.cxx ├── event │ └── data │ │ ├── 01.xml │ │ └── 01.out ├── Makefile.am ├── CMakeLists.txt └── test_main.cxx ├── examples ├── 04-xslt │ ├── example.xml │ ├── CMakeLists.txt │ ├── Makefile.am │ ├── example.xsl │ └── example.cxx ├── Makefile.am ├── 01-tree_parsing │ ├── Makefile.am │ ├── CMakeLists.txt │ └── example.cxx ├── 02-event_parsing │ ├── Makefile.am │ ├── CMakeLists.txt │ └── example.cxx ├── 05-xpath │ ├── CMakeLists.txt │ ├── example.xml │ ├── Makefile.am │ └── example.cxx ├── 03-xml_generation │ ├── Makefile.am │ ├── CMakeLists.txt │ └── example.cxx ├── CMakeLists.txt └── cmake │ ├── find_package │ ├── example.cpp │ └── CMakeLists.txt │ └── add_subdirectory │ ├── example.cpp │ └── CMakeLists.txt ├── scripts ├── ci │ ├── install-redhat.sh │ ├── install-macos.sh │ ├── common.sh │ ├── autoconf.sh │ ├── install.sh │ └── install-debian.sh └── install_deps.sh ├── xmlwrapp.pc.in ├── xsltwrapp.pc.in ├── docs ├── Makefile.am ├── manual │ ├── whatnext.doxygen │ ├── mainpage.doxygen │ ├── xslt.doxygen │ ├── tips.doxygen │ ├── prepare.doxygen │ └── attributes.doxygen └── CMakeLists.txt ├── .gitignore ├── platform └── Win32 │ ├── README │ ├── xsltwrapp.vcxproj.filters │ ├── test.vcxproj.filters │ ├── libxml.props │ └── xmlwrapp.sln ├── AUTHORS ├── include ├── Makefile.am ├── CMakeLists.txt ├── xsltwrapp │ ├── xsltwrapp.h │ └── init.h └── xmlwrapp │ ├── xmlwrapp.h │ ├── _cbfo.h │ ├── schema.h │ └── relaxng.h ├── Makefile.am ├── xmlwrapp-config.in ├── .git-blame-ignore-revs ├── .github └── workflows │ ├── release.yml │ └── build_msw_xml_libs.yml ├── admin ├── ax_require_defined.m4 ├── ax_append_flag.m4 ├── ax_append_compile_flags.m4 ├── ax_check_compile_flag.m4 └── visibility.m4 ├── src ├── Makefile.am ├── libxml │ ├── version.cxx │ ├── utility.cxx │ ├── ait_impl.h │ ├── dtd_impl.h │ ├── dtd_impl.cxx │ ├── init.cxx │ ├── node_manip.h │ ├── node_iterator.h │ ├── utility.h │ ├── relaxng.cxx │ ├── schema.cxx │ ├── errors_impl.h │ └── nodes_view.cxx ├── libxslt │ ├── init.cxx │ └── result.h └── CMakeLists.txt ├── LICENSE └── README.md /tests/node/data/empty.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/06a.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/07a.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/document/data/13a.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/02.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/07b.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/06b.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/07c.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/tree/data/bad.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/01a.out: -------------------------------------------------------------------------------- 1 | a=a 2 | b=b 3 | c=c 4 | d=d 5 | -------------------------------------------------------------------------------- /tests/attributes/data/01b.out: -------------------------------------------------------------------------------- 1 | a=a 2 | a=ta 3 | b=b 4 | b=tb 5 | -------------------------------------------------------------------------------- /tests/node/data/04c.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/xslt/data/01a.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/attributes/data/01a.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/03.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/07d.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/document/data/02.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/document/data/03.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/document/data/09.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/document/data/10.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/node/data/05b.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/node/data/05d.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/attributes/data/02.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/document/data/04.out: -------------------------------------------------------------------------------- 1 | 2 | pcdata 3 | -------------------------------------------------------------------------------- /tests/node/data/14.out: -------------------------------------------------------------------------------- 1 | 2 | some text 3 | -------------------------------------------------------------------------------- /tests/attributes/data/01c.out: -------------------------------------------------------------------------------- 1 | first=this & that 2 | second=who is on first? 3 | -------------------------------------------------------------------------------- /tests/attributes/data/08.out: -------------------------------------------------------------------------------- 1 | first_attr=1 2 | second_attr=2 3 | thrid_attr=3 4 | -------------------------------------------------------------------------------- /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/13b.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/document/data/13b.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/document/data/14inc.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/node/data/06a.xml: -------------------------------------------------------------------------------- 1 | Title 2 | -------------------------------------------------------------------------------- /tests/node/data/10.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/node/data/11.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/relaxng/data/invalid.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/schema/data/invalid.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/xslt/data/input.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/attributes/data/08.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/09.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/node/data/09.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/tree/data/good.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/xpath/data/01.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/attributes/data/01c.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/document/data/01.out: -------------------------------------------------------------------------------- 1 | type_pi 2 | type_comment 3 | type_element 4 | type_comment 5 | -------------------------------------------------------------------------------- /tests/document/data/15.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/node/data/05.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/node/data/special_chars.xml: -------------------------------------------------------------------------------- 1 | 2 | Marlow & Sons 3 | -------------------------------------------------------------------------------- /tests/relaxng/data/nonvalid.xml: -------------------------------------------------------------------------------- 1 | 2 | YYY 3 | ZZZ 4 | 5 | -------------------------------------------------------------------------------- /tests/relaxng/data/valid.xml: -------------------------------------------------------------------------------- 1 | 2 | ZZZ 3 | YYY 4 | 5 | -------------------------------------------------------------------------------- /tests/schema/data/valid.xml: -------------------------------------------------------------------------------- 1 | 2 | ZZZ 3 | YYY 4 | 5 | -------------------------------------------------------------------------------- /tests/document/data/21.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /tests/node/data/03b.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/attributes/data/04.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/10.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /tests/document/data/19.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /tests/node/data/04b.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/node/data/06a.out: -------------------------------------------------------------------------------- 1 | type_element 2 | type_element 3 | type_element 4 | type_text 5 | -------------------------------------------------------------------------------- /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/document/data/08.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | pcdata 5 | -------------------------------------------------------------------------------- /tests/node/data/03a.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/node/data/04.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/node/data/06c.out: -------------------------------------------------------------------------------- 1 | type_element 2 | type_entity_ref 3 | type_dtd_entity 4 | type_text 5 | -------------------------------------------------------------------------------- /tests/xslt/data/02a.out: -------------------------------------------------------------------------------- 1 |

root

2 |

child

3 |

child

4 | 5 | -------------------------------------------------------------------------------- /tests/attributes/data/01b.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/attributes/data/10.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | See? 4 | -------------------------------------------------------------------------------- /tests/node/data/02a.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | Peter 4 | CO 5 | 6 | -------------------------------------------------------------------------------- /tests/xslt/data/03a.out: -------------------------------------------------------------------------------- 1 | foo == bar

root

2 |

child

3 |

child

4 | 5 | -------------------------------------------------------------------------------- /tests/document/data/01.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/node/data/03.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/node/data/06c.xml: -------------------------------------------------------------------------------- 1 | 3 | ]> 4 | &myname; 5 | -------------------------------------------------------------------------------- /tests/node/data/namespace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/node/data/06b.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | <![CDATA[text]]> 4 | 5 | -------------------------------------------------------------------------------- /tests/node/data/namespace.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/node/data/04a.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /tests/xpath/data/02.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /examples/04-xslt/example.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/document/data/17.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /tests/node/data/08a.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/document/data/14.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /scripts/ci/install-macos.sh: -------------------------------------------------------------------------------- 1 | # Used to install dependencies for the CI builds under macOS. 2 | 3 | if [ -z "$XMLWRAPP_CMAKE" ]; then 4 | brew install automake 5 | fi 6 | -------------------------------------------------------------------------------- /tests/attributes/data/09.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/node/data/01.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | one 4 | two 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/node/data/05a.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/node/data/05c.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/node/data/08a.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/tree/data/output: -------------------------------------------------------------------------------- 1 | root 2 | a 3 | b 4 | c 5 | d 6 | e 7 | f 8 | g 9 | -------------------------------------------------------------------------------- /tests/xslt/data/01b.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /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/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/04-xslt/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(example04 example.cxx) 2 | target_include_directories(example04 PRIVATE ${PROJECT_SOURCE_DIR}/include) 3 | target_link_libraries(example04 xsltwrapp) 4 | -------------------------------------------------------------------------------- /examples/05-xpath/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(example05 example.cxx) 2 | target_include_directories(example05 PRIVATE ${PROJECT_SOURCE_DIR}/include) 3 | target_link_libraries(example05 xmlwrapp) 4 | -------------------------------------------------------------------------------- /examples/05-xpath/example.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/document/data/14.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /examples/01-tree_parsing/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(example01 example.cxx) 2 | target_include_directories(example01 PRIVATE ${PROJECT_SOURCE_DIR}/include) 3 | target_link_libraries(example01 xmlwrapp) 4 | -------------------------------------------------------------------------------- /examples/02-event_parsing/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(example02 example.cxx) 2 | target_include_directories(example02 PRIVATE ${PROJECT_SOURCE_DIR}/include) 3 | target_link_libraries(example02 xmlwrapp) 4 | -------------------------------------------------------------------------------- /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/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(example03 example.cxx) 2 | target_include_directories(example03 PRIVATE ${PROJECT_SOURCE_DIR}/include) 3 | target_link_libraries(example03 xmlwrapp) 4 | -------------------------------------------------------------------------------- /tests/node/data/02.xml: -------------------------------------------------------------------------------- 1 | PeterCOIsaacCAAlbertAZ 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/node/data/07a.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /tests/xslt/data/01c.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tests/node/data/07a.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(01-tree_parsing) 2 | add_subdirectory(02-event_parsing) 3 | add_subdirectory(03-xml_generation) 4 | if(XMLWRAPP_WITH_LIBXSLT) 5 | add_subdirectory(04-xslt) 6 | endif(XMLWRAPP_WITH_LIBXSLT) 7 | add_subdirectory(05-xpath) 8 | -------------------------------------------------------------------------------- /tests/node/data/07b.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /tests/node/data/07b.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /xmlwrapp.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: xmlwrapp 7 | Version: @VERSION@ 8 | Description: A C++ wrapper around libxml2 9 | Requires: libxml-2.0 10 | Libs: -L${libdir} -lxmlwrapp 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/event/data/01.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/node/data/copy_ns.out: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /xsltwrapp.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: xsltwrapp 7 | Version: @VERSION@ 8 | Description: A C++ wrapper around libxslt 9 | Requires: xmlwrapp = @VERSION@, libexslt, libxslt 10 | Libs: -L${libdir} -lxsltwrapp 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/schema/data/schema.xsd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /tests/xslt/data/02a.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

root

5 |

child

6 |
7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/xslt/data/03a.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | foo == 5 |

root

6 |

child

7 |
8 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/*.sln \ 31 | $(srcdir)/platform/Win32/*.vcxproj \ 32 | $(srcdir)/platform/Win32/*.vcxproj.filters \ 33 | $(srcdir)/platform/Win32/libxml.props 34 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(XMLWRAPP_HEADERS 2 | xmlwrapp/attributes.h 3 | xmlwrapp/_cbfo.h 4 | xmlwrapp/document.h 5 | xmlwrapp/event_parser.h 6 | xmlwrapp/errors.h 7 | xmlwrapp/export.h 8 | xmlwrapp/init.h 9 | xmlwrapp/node.h 10 | xmlwrapp/nodes_view.h 11 | xmlwrapp/relaxng.h 12 | xmlwrapp/schema.h 13 | xmlwrapp/tree_parser.h 14 | xmlwrapp/version.h 15 | xmlwrapp/xmlwrapp.h 16 | xmlwrapp/xpath.h 17 | ) 18 | 19 | set(XSLTWRAPP_HEADERS 20 | xsltwrapp/init.h 21 | xsltwrapp/stylesheet.h 22 | xsltwrapp/xsltwrapp.h 23 | ) 24 | 25 | install(FILES ${XMLWRAPP_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/xmlwrapp) 26 | 27 | if( XMLWRAPP_WITH_LIBXSLT ) 28 | install (FILES ${XSLTWRAPP_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/xsltwrapp) 29 | endif( XMLWRAPP_WITH_LIBXSLT ) 30 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 < 2 | 3 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.git-blame-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 .git-blame-ignore-revs 9 | # 10 | # When adding entries to this file, please keep them in reverse chronological 11 | # order (the newest ones are added at the top). 12 | # 13 | # You can use 14 | # 15 | # $ git show -s --format='# %s, %cs%n%H%n' 16 | # 17 | # incantation to directly create an entry in the format used here. 18 | 19 | # Reformat CMake files, 2025-07-16 20 | fb4951053817c8218146a31ff7dacca842b08140 21 | 22 | # Reformatted source code for better readibility., 2009-12-20 23 | 58ab58f90d6d973cdbca3e3e49ffa3e71df6c24f 24 | -------------------------------------------------------------------------------- /docs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Prepare configuration options 2 | 3 | # See if we can find doxygen, if so, build the docs 4 | 5 | #find_program(DOXYGEN doxygen) 6 | find_package(Doxygen) 7 | 8 | if(DOXYGEN_FOUND) 9 | file(GLOB MANUAL_SOURCES "manual/*.doxygen") 10 | file(GLOB ALL_HEADERS "${CMAKE_SOURCE_DIR}/include/*/*.h") 11 | 12 | add_custom_target(xmlwrapp_docs ALL DEPENDS html/index.html) 13 | add_custom_command( 14 | OUTPUT 15 | html/index.html 16 | COMMAND 17 | ${CMAKE_COMMAND} -E env 18 | DOXYGEN_OUTPUT_DIRECTORY_SLASH=${CMAKE_CURRENT_BINARY_DIR}/ 19 | ${DOXYGEN_EXECUTABLE} Doxyfile 20 | MAIN_DEPENDENCY Doxyfile 21 | DEPENDS ${MANUAL_SOURCES} ${ALL_HEADERS} 22 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 23 | COMMENT "Generating API documentation with Doxygen" 24 | VERBATIM 25 | ) 26 | install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html" DESTINATION ${CMAKE_INSTALL_DOCDIR}) 27 | else() 28 | message(WARNING "Doxygen not found, documentation will not be built.") 29 | set(XMLWRAPP_DOC OFF PARENT_SCOPE) 30 | endif(DOXYGEN_FOUND) 31 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | # This manually triggered workflow creates a new release. 2 | name: Create Release 3 | 4 | on: 5 | workflow_dispatch: 6 | push: 7 | tags: 8 | - "v*.*.*" 9 | 10 | permissions: 11 | contents: write 12 | 13 | jobs: 14 | make_release: 15 | runs-on: ubuntu-24.04 16 | name: Create Release Source Archives 17 | env: 18 | XMLWRAPP_WITH_DOCS: 1 19 | XMLWRAPP_CMAKE: 1 20 | steps: 21 | - name: Checkout 22 | uses: actions/checkout@v4 23 | 24 | - name: Install dependencies 25 | run: ./scripts/ci/install.sh 26 | 27 | - name: Configure 28 | run: cmake -S . -B ../build-cmake 29 | 30 | - name: Create release archives 31 | run: cmake --build ../build-cmake --target dist 32 | 33 | - name: Check release archives 34 | run: cmake --build ../build-cmake --target distcheck 35 | 36 | - name: Create GitHub release 37 | uses: softprops/action-gh-release@v2.2.2 38 | with: 39 | files: ../build-cmake/xmlwrapp-*.tar.*z 40 | fail_on_unmatched_files: true 41 | draft: true 42 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TEST_SRCS 2 | test.h 3 | test_main.cxx 4 | attributes/test_attributes.cxx 5 | document/test_document.cxx 6 | event/test_event.cxx 7 | node/test_node.cxx 8 | tree/test_tree.cxx 9 | schema/test_schema.cxx 10 | xpath/test_xpath.cxx 11 | ) 12 | 13 | set(TEST_DATA_DIRS attributes document event node tree schema xpath) 14 | 15 | if(XMLWRAPP_WITH_LIBXSLT) 16 | LIST(APPEND TEST_SRCS xslt/test_xslt.cxx) 17 | LIST(APPEND TEST_DATA_DIRS xslt) 18 | endif(XMLWRAPP_WITH_LIBXSLT) 19 | 20 | add_executable(test_xmlwrapp ${TEST_SRCS}) 21 | 22 | target_include_directories(test_xmlwrapp PRIVATE ${PROJECT_SOURCE_DIR}/include) 23 | 24 | if(XMLWRAPP_WITH_LIBXSLT) 25 | target_link_libraries(test_xmlwrapp xsltwrapp) 26 | else() 27 | target_link_libraries(test_xmlwrapp xmlwrapp) 28 | endif(XMLWRAPP_WITH_LIBXSLT) 29 | 30 | add_test(NAME "test_xmlwrapp" COMMAND test_xmlwrapp) 31 | 32 | # Allow test must to find the data files (alternative could be to run it in 33 | # this directory using WORKING_DIRECTORY in add_test() above, but this seems 34 | # better because it's more explicit). 35 | set_tests_properties(test_xmlwrapp 36 | PROPERTIES 37 | ENVIRONMENT "srcdir=${CMAKE_CURRENT_SOURCE_DIR}" 38 | ) 39 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /scripts/ci/autoconf.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 [ "$XMLWRAPP_WITH_DOCS" != 1 ]; then 28 | configure_args="$configure_args --disable-docs" 29 | fi 30 | 31 | ./configure CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS" $configure_args 32 | 33 | make -j`nproc` --keep-going 34 | 35 | if ! make check; then 36 | echo 'Test suite log contents' 37 | echo '-----------------------' 38 | cat tests/test-suite.log 39 | echo '-----------------------' 40 | exit 1 41 | fi 42 | -------------------------------------------------------------------------------- /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/version.cxx \ 37 | libxml/xpath.cxx 38 | 39 | 40 | if WITH_XSLT 41 | 42 | libxsltwrapp_la_CPPFLAGS = -DXSLTWRAPP_BUILD -DXMLWRAPP_USE_DLL $(AM_CPPFLAGS) $(LIBEXSLT_CFLAGS) $(LIBXSLT_CFLAGS) 43 | libxsltwrapp_la_LIBADD = libxmlwrapp.la $(LIBEXSLT_LIBS) $(LIBXSLT_LIBS) 44 | libxsltwrapp_la_LDFLAGS = -version-info 4:0:0 -no-undefined 45 | 46 | libxsltwrapp_la_SOURCES = \ 47 | libxslt/init.cxx \ 48 | libxslt/result.h \ 49 | libxslt/stylesheet.cxx 50 | 51 | endif 52 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /scripts/ci/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Used to install dependencies for the CI builds. 3 | set -e 4 | 5 | # This function sets the environment variable to the given value not only for 6 | # this script itself, but persistently, by using GITHUB_ENV feature provided 7 | # by the CI environment. 8 | set_env_var() { 9 | echo "Setting environment variable $1=$2" 10 | echo $1=$2 >> $GITHUB_ENV 11 | eval "export $1=$2" 12 | } 13 | 14 | echo 'Compiler version:' 15 | ${CXX-c++} --version 16 | 17 | case $(uname -s) in 18 | Linux) 19 | if [ -f /etc/apt/sources.list ]; then 20 | platform=debian 21 | elif [ -f /etc/redhat-release ]; then 22 | platform=redhat 23 | else 24 | echo 'Unknown Linux distribution.' >&2 25 | exit 1 26 | fi 27 | ccache_path=/usr/lib/ccache 28 | ;; 29 | 30 | Darwin) 31 | platform=macos 32 | # The directory used for ccache symlinks has changed and differs between 33 | # macOS 13 and 15, so detect it dynamically. 34 | if [ -d /opt/homebrew/opt/ccache/libexec ]; then 35 | ccache_path=/opt/homebrew/opt/ccache/libexec 36 | elif [ -d /usr/local/opt/ccache/libexec ]; then 37 | ccache_path=/usr/local/opt/ccache/libexec 38 | else 39 | echo 'Warning: unknown macOS ccache path.' >&2 40 | fi 41 | ;; 42 | 43 | *) 44 | echo "Unknown platform `uname`." >&2 45 | exit 1 46 | esac 47 | 48 | set_env_var PATH ${ccache_path}:$PATH 49 | set_env_var XMLWRAPP_SOURCE_DIR $GITHUB_WORKSPACE 50 | 51 | . ${XMLWRAPP_SOURCE_DIR}/scripts/ci/common.sh 52 | 53 | . ${XMLWRAPP_SOURCE_DIR}/scripts/ci/install-${platform}.sh 54 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /examples/cmake/find_package/example.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2025 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 | // xmlwrapp include 34 | #include 35 | 36 | // standard includes 37 | #include 38 | 39 | int main() { 40 | std::printf("Using xmlwrapp v%s.\n", xml::get_version_string()); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /examples/cmake/add_subdirectory/example.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2025 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 | // xmlwrapp include 34 | #include 35 | 36 | // standard includes 37 | #include 38 | 39 | int main() { 40 | std::printf("Using xmlwrapp v%s.\n", xml::get_version_string()); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /examples/cmake/find_package/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2025 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 are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this 9 | # list of conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation 13 | # and/or other materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its 16 | # contributors may be used to endorse or promote products derived from 17 | # this software without specific prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | # This is the simplest possible example of using xmlwrapp in a CMake-based project. 31 | cmake_minimum_required(VERSION 3.16) 32 | 33 | project(XmlwrappFindPackageExample 34 | DESCRIPTION "Example of using xmlwrapp with CMake find_package" 35 | LANGUAGES CXX 36 | ) 37 | 38 | find_package(Xmlwrapp 0.10 REQUIRED) 39 | 40 | add_executable(example example.cpp) 41 | target_link_libraries(example PRIVATE xmlwrapp::xmlwrapp) 42 | -------------------------------------------------------------------------------- /scripts/ci/install-debian.sh: -------------------------------------------------------------------------------- 1 | # Used to install dependencies for the CI builds under Debian/Ubuntu. 2 | 3 | export DEBIAN_FRONTEND=noninteractive 4 | 5 | run_apt_install() { 6 | echo "-> Running apt-get install $@" 7 | 8 | # Disable some (but not all) output. 9 | sudo apt-get -q -o=Dpkg::Use-Pty=0 install -y "$@" 10 | 11 | rc=$? 12 | echo "-> Done with $rc" 13 | 14 | return $rc 15 | } 16 | 17 | # Arch-independent dependencies. 18 | sudo apt-get update -qq 19 | 20 | if [ "$XMLWRAPP_WITH_DOCS" = 1 ]; then 21 | doc_packages='doxygen graphviz' 22 | fi 23 | 24 | case "$HOST" in 25 | *-w64-mingw32) 26 | arch=`echo $HOST | sed -e 's/-w64-mingw32$//;s/_/-/'` 27 | 28 | case "$arch" in 29 | i686) 30 | sudo dpkg --add-architecture i386 31 | 32 | # Workaround for https://github.com/actions/runner-images/issues/4589 33 | # (normally only apt-get update should have been needed) 34 | sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list 35 | sudo apt-get update -qq 36 | sudo apt-get remove -qq libmono* moby* mono* nginx* php* libgdiplus libpcre2-posix3 libzip4 37 | 38 | wine_package=wine32-development 39 | ;; 40 | 41 | x86-64) 42 | wine_package=wine64-development 43 | ;; 44 | 45 | *) 46 | echo "Unknown architecture $arch when cross-compiling" 47 | exit 1 48 | ;; 49 | esac 50 | 51 | run_apt_install $doc_packages g++-mingw-w64-$arch $wine_package wine-development 52 | 53 | echo -n "Cross-compiling for $HOST using " 54 | $HOST-g++ --version 55 | 56 | # Download the previously built required dependencies. 57 | wget --no-verbose https://github.com/vslavik/xmlwrapp/releases/download/xmllibs/xmllibs-${HOST}.zip 58 | sudo unzip -q xmllibs-${HOST}.zip -d /usr/local 59 | ;; 60 | 61 | *) 62 | # Assume native build. 63 | run_apt_install $doc_packages libxml2-dev libxslt1-dev 64 | ;; 65 | esac 66 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /examples/cmake/add_subdirectory/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2025 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 are met: 7 | # 8 | # 1. Redistributions of source code must retain the above copyright notice, this 9 | # list of conditions and the following disclaimer. 10 | # 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, 12 | # this list of conditions and the following disclaimer in the documentation 13 | # and/or other materials provided with the distribution. 14 | # 15 | # 3. Neither the name of the copyright holder nor the names of its 16 | # contributors may be used to endorse or promote products derived from 17 | # this software without specific prior written permission. 18 | # 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | # This is an example of using uninstalled xmlwrapp (typically included as a 31 | # submodule) in a CMake-based project. 32 | cmake_minimum_required(VERSION 3.16) 33 | 34 | project(XmlwrappAddSubdirectoryExample 35 | DESCRIPTION "Example of using xmlwrapp with CMake add_subdirectory" 36 | LANGUAGES CXX 37 | ) 38 | 39 | # As this project doesn't use it, disable building xsltwrapp library. 40 | set(XMLWRAPP_WITH_LIBXSLT OFF) 41 | 42 | # In a real program this would be an actual subdirectory and not a parent one. 43 | add_subdirectory(../../.. ${CMAKE_CURRENT_BINARY_DIR}/xmlwrapp) 44 | 45 | add_executable(example example.cpp) 46 | target_link_libraries(example PRIVATE xmlwrapp::xmlwrapp) 47 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/libxml/version.cxx: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2025 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 | // xmlwrapp includes 35 | #include "xmlwrapp/version.h" 36 | 37 | namespace xml 38 | { 39 | 40 | // Note that even though these functions are trivial, they must not be declared 41 | // inline as the program uses them to get the values from the library actually 42 | // used at run-time and not the values that were used when compiling. 43 | 44 | int get_major_version() 45 | { 46 | return XMLWRAPP_VERSION_MAJOR; 47 | } 48 | 49 | int get_minor_version() 50 | { 51 | return XMLWRAPP_VERSION_MINOR; 52 | } 53 | 54 | int get_micro_version() 55 | { 56 | return XMLWRAPP_VERSION_MICRO; 57 | } 58 | 59 | const char* get_version_string() 60 | { 61 | return XMLWRAPP_VERSION_STRING; 62 | } 63 | 64 | bool check_version(int major, int minor, int micro) 65 | { 66 | return XMLWRAPP_CHECK_VERSION(major, minor, micro); 67 | } 68 | 69 | } // namespace xml 70 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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.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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 0. Introduction 2 | 3 | xmlwrapp is a modern style C++ library for working with XML data, built atop 4 | the venerable libxml2 C library. 5 | 6 | Additional resources, bug reports, latest sources etc. can be found on the 7 | [project page](https://vslavik.github.io/xmlwrapp/). 8 | 9 | Packages tarballs can be downloaded from the same location or from the 10 | [release page](https://github.com/vslavik/xmlwrapp/releases). 11 | 12 | If you need help or want to discuss xmlwrapp, feel free to join the discussion 13 | group hosted at [Google Groups](https://groups.google.com/group/xmlwrapp) 14 | or email directly to xmlwrapp@googlegroups.com. 15 | 16 | 17 | ## 1. Requirements 18 | 19 | In order to build xmlwrapp, you need libxml2 version 2.4.28 or newer. When 20 | building with XSLT support, libxslt 1.1.6 or newer is required. Both libraries 21 | are available from [libxml2 home page](https://xmlsoft.org). 22 | 23 | 24 | ## 2. Building on Unix 25 | 26 | On Unix, either autotools-based build system or CMake can be used. 27 | 28 | ### Building using Autotools 29 | 30 | Building xmlwrapp is 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 | ### Building using CMake 49 | 50 | Building xmlwrapp using CMake is also straightforward. Just do the following: 51 | 52 | $ cmake -S . -B build-dir 53 | $ cmake --build build-dir 54 | $ cmake --install build-dir 55 | 56 | The usual CMake `BUILD_SHARED_LIBS` option is supported for selecting whether 57 | shared (default) or static libraries should be built, use `cmake -L` to see the 58 | other available options. 59 | 60 | 61 | ## 3. Building on Windows 62 | 63 | The library can be built either with Microsoft Visual C++ compiler, using the 64 | project files from located in platform/Win32 directory or in the same way as 65 | under Unix, i.e. with configure and make, if you have Cygwin installed (note 66 | that MinGW can be used as a cross-compiler under Cygwin, producing native 67 | libraries without any Cygwin dependencies). In either case, you will need to 68 | either build libxml and libxslt for Windows yourself or download the already 69 | built versions from http://www.zlatkovic.com/libxml.en.html or elsewhere. 70 | 71 | 72 | ## Using xmlwrapp 73 | 74 | On Unix, you should use pkg-config to get compiler flags for xmlwrapp or 75 | xsltwrapp libraries: 76 | 77 | $ c++ -c `pkg-config --cflags xmlwrapp` ... 78 | $ c++ -o ... `pkg-config --libs xmlwrapp` 79 | 80 | On Windows, you need to link against xmlwrapp libraries and add the include/ 81 | directory to compiler's headers search path. 82 | 83 | Under either platform you may consume the library using CMake in the usual way, 84 | i.e. using either `find_package(xmlwrapp)` or `add_subdirectory(xmlwrapp)` and 85 | then linking to the `xmlwrapp::xmlwrapp` target. 86 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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_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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Configure shared library with the given name and (full) ELF version. 2 | # 3 | # Set properties for using hidden ELF visibility, defining proper DLL-related 4 | # symbols and use $ORIGIN in the runpath. 5 | # 6 | # Note that this does nothing when shared libraries are not used. 7 | function(setup_shared_library target version) 8 | if (XMLWRAPP_SHARED) 9 | # Construct XMLWRAPP_USE_DLL or XSLTWRAPP_USE_DLL symbol name. 10 | string(TOUPPER "${target}_USE_DLL" use_dll_symbol) 11 | target_compile_definitions(${target} 12 | PRIVATE 13 | HAVE_VISIBILITY 14 | INTERFACE 15 | ${use_dll_symbol} 16 | ) 17 | 18 | # Set SOVERSION to the major VERSION component. 19 | string(REPLACE "." ";" version_as_list ${version}) 20 | list(GET version_as_list 0 soversion) 21 | 22 | set(output_name "${target}") 23 | if( XMLWRAPP_NAME_PREFIX ) 24 | set(output_name "${XMLWRAPP_NAME_PREFIX}${output_name}") 25 | endif() 26 | if( XMLWRAPP_NAME_SUFFIX ) 27 | set(output_name "${output_name}${XMLWRAPP_NAME_SUFFIX}") 28 | endif() 29 | 30 | set_target_properties(${target} PROPERTIES 31 | OUTPUT_NAME ${output_name} 32 | BUILD_RPATH_USE_ORIGIN ON 33 | DEFINE_SYMBOL "DLL_EXPORT" 34 | CXX_VISIBILITY_PRESET hidden 35 | VISIBILITY_INLINES_HIDDEN ON 36 | VERSION ${version} 37 | SOVERSION ${soversion} 38 | ) 39 | endif() 40 | endfunction() 41 | 42 | add_library(xmlwrapp ${XMLWRAPP_LIB_TYPE}) 43 | target_sources(xmlwrapp 44 | PRIVATE 45 | libxml/ait_impl.cxx 46 | libxml/ait_impl.h 47 | libxml/attributes.cxx 48 | libxml/document.cxx 49 | libxml/dtd_impl.cxx 50 | libxml/dtd_impl.h 51 | libxml/errors.cxx 52 | libxml/errors_impl.h 53 | libxml/event_parser.cxx 54 | libxml/init.cxx 55 | libxml/node.cxx 56 | libxml/node_iterator.cxx 57 | libxml/node_iterator.h 58 | libxml/node_manip.cxx 59 | libxml/node_manip.h 60 | libxml/nodes_view.cxx 61 | libxml/relaxng.cxx 62 | libxml/schema.cxx 63 | libxml/tree_parser.cxx 64 | libxml/utility.cxx 65 | libxml/utility.h 66 | libxml/version.cxx 67 | libxml/xpath.cxx 68 | ) 69 | 70 | target_include_directories(xmlwrapp 71 | PRIVATE 72 | ${LIBXML2_INCLUDE_DIRS} 73 | PUBLIC 74 | $ 75 | $ 76 | ) 77 | target_link_options(xmlwrapp 78 | PUBLIC 79 | ${LIBXML2_LDFLAGS} 80 | ) 81 | target_link_libraries(xmlwrapp 82 | PUBLIC 83 | ${LIBXML2_LIBRARIES} 84 | ) 85 | setup_shared_library(xmlwrapp 6.0.0) 86 | install (TARGETS xmlwrapp EXPORT XmlwrappTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}) 87 | 88 | add_library(xmlwrapp::xmlwrapp ALIAS xmlwrapp) 89 | 90 | if( XMLWRAPP_WITH_LIBXSLT ) 91 | add_library(xsltwrapp ${XMLWRAPP_LIB_TYPE}) 92 | target_sources(xsltwrapp 93 | PRIVATE 94 | libxslt/init.cxx 95 | libxslt/stylesheet.cxx 96 | libxslt/result.h 97 | ) 98 | target_include_directories(xsltwrapp 99 | PRIVATE 100 | ${LIBXSLT_INCLUDE_DIRS} 101 | ${LIBEXSLT_INCLUDE_DIRS} 102 | PUBLIC 103 | $ 104 | $ 105 | ) 106 | target_link_options(xsltwrapp 107 | PUBLIC 108 | ${LIBXSLT_LDFLAGS} 109 | ${LIBEXSLT_LDFLAGS} 110 | ) 111 | target_link_libraries(xsltwrapp 112 | PUBLIC 113 | xmlwrapp 114 | ${LIBXSLT_LIBRARIES} 115 | ${LIBEXSLT_LIBRARIES} 116 | ) 117 | setup_shared_library(xsltwrapp 4.0.0) 118 | install (TARGETS xsltwrapp EXPORT XmlwrappTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}) 119 | 120 | add_library(xmlwrapp::xsltwrapp ALIAS xsltwrapp) 121 | endif( XMLWRAPP_WITH_LIBXSLT ) 122 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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/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/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 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------