summaryrefslogtreecommitdiff
path: root/doc/examples
diff options
context:
space:
mode:
Diffstat (limited to 'doc/examples')
-rw-r--r--doc/examples/Makefile.am93
-rw-r--r--doc/examples/Makefile.in665
-rw-r--r--doc/examples/examples.xml602
-rw-r--r--doc/examples/examples.xsl169
-rwxr-xr-xdoc/examples/index.py296
-rw-r--r--doc/examples/io1.c166
-rw-r--r--doc/examples/io1.res5
-rw-r--r--doc/examples/parse1.c56
-rw-r--r--doc/examples/parse2.c72
-rw-r--r--doc/examples/reader1.c107
-rw-r--r--doc/examples/reader1.res14
-rw-r--r--doc/examples/reader2.c122
-rw-r--r--doc/examples/reader3.c119
-rw-r--r--doc/examples/reader3.res13
-rw-r--r--doc/examples/test1.xml1
-rw-r--r--doc/examples/test2.xml13
-rw-r--r--doc/examples/test3.xml39
-rw-r--r--doc/examples/testWriter.c1198
-rw-r--r--doc/examples/tree1.c94
-rw-r--r--doc/examples/tree1.res4
-rw-r--r--doc/examples/tree2.c118
-rw-r--r--doc/examples/tree2.res18
-rw-r--r--doc/examples/writer.xml2
-rw-r--r--doc/examples/xpath1.c249
24 files changed, 4235 insertions, 0 deletions
diff --git a/doc/examples/Makefile.am b/doc/examples/Makefile.am
new file mode 100644
index 0000000..754e663
--- /dev/null
+++ b/doc/examples/Makefile.am
@@ -0,0 +1,93 @@
+# Beware this is autogenerated by index.py
+INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I@srcdir@/include @THREAD_CFLAGS@ @Z_CFLAGS@
+DEPS = $(top_builddir)/libxml2.la
+LDADDS = @STATIC_BINARIES@ $(top_builddir)/libxml2.la @THREAD_LIBS@ @Z_LIBS@ $(ICONV_LIBS) -lm @WIN32_EXTRA_LIBADD@
+
+rebuild: examples.xml index.html
+
+examples.xml: index.py *.c
+ -@($(srcdir)/index.py)
+
+index.html: examples.xml examples.xsl
+ -@(xsltproc examples.xsl examples.xml && echo "Rebuilt web page" && xmllint --valid --noout index.html)
+
+install-data-local:
+ $(mkinstalldirs) $(DESTDIR)$(HTML_DIR)
+ -@INSTALL@ -m 0644 $(srcdir)/*.html $(srcdir)/*.c $(srcdir)/*.xml $(srcdir)/*.xsl $(srcdir)/*.res $(DESTDIR)$(HTML_DIR)
+
+EXTRA_DIST=examples.xsl index.py test1.xml examples.xml test2.xml writer.xml test3.xml reader1.res reader3.res tree1.res tree2.res io1.res
+
+noinst_PROGRAMS=xpath1 parse1 parse2 tree1 tree2 testWriter reader1 reader2 reader3 io1
+
+xpath1_SOURCES=xpath1.c
+xpath1_LDFLAGS=
+xpath1_DEPENDENCIES= $(DEPS)
+xpath1_LDADD= @RDL_LIBS@ $(LDADDS)
+
+parse1_SOURCES=parse1.c
+parse1_LDFLAGS=
+parse1_DEPENDENCIES= $(DEPS)
+parse1_LDADD= @RDL_LIBS@ $(LDADDS)
+
+parse2_SOURCES=parse2.c
+parse2_LDFLAGS=
+parse2_DEPENDENCIES= $(DEPS)
+parse2_LDADD= @RDL_LIBS@ $(LDADDS)
+
+tree1_SOURCES=tree1.c
+tree1_LDFLAGS=
+tree1_DEPENDENCIES= $(DEPS)
+tree1_LDADD= @RDL_LIBS@ $(LDADDS)
+
+tree2_SOURCES=tree2.c
+tree2_LDFLAGS=
+tree2_DEPENDENCIES= $(DEPS)
+tree2_LDADD= @RDL_LIBS@ $(LDADDS)
+
+testWriter_SOURCES=testWriter.c
+testWriter_LDFLAGS=
+testWriter_DEPENDENCIES= $(DEPS)
+testWriter_LDADD= @RDL_LIBS@ $(LDADDS)
+
+reader1_SOURCES=reader1.c
+reader1_LDFLAGS=
+reader1_DEPENDENCIES= $(DEPS)
+reader1_LDADD= @RDL_LIBS@ $(LDADDS)
+
+reader2_SOURCES=reader2.c
+reader2_LDFLAGS=
+reader2_DEPENDENCIES= $(DEPS)
+reader2_LDADD= @RDL_LIBS@ $(LDADDS)
+
+reader3_SOURCES=reader3.c
+reader3_LDFLAGS=
+reader3_DEPENDENCIES= $(DEPS)
+reader3_LDADD= @RDL_LIBS@ $(LDADDS)
+
+io1_SOURCES=io1.c
+io1_LDFLAGS=
+io1_DEPENDENCIES= $(DEPS)
+io1_LDADD= @RDL_LIBS@ $(LDADDS)
+
+tests: $(noinst_PROGRAMS)
+ @(echo > .memdump)
+ @(./parse1 test1.xml)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+ @(./parse2 test2.xml)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+ @(./tree1 test2.xml > tree1.tmp ; diff tree1.tmp tree1.res ; rm tree1.tmp)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+ @(./tree2 > tree2.tmp ; diff tree2.tmp tree2.res ; rm tree2.tmp)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+ @(./testWriter ; for i in 1 2 3 4 ; do diff writer.xml writer$$i.res ; done ; rm writer*.res)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+ @(./reader1 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+ @(./reader2 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+ @(./reader3 > reader3.tmp ; diff reader3.tmp reader3.res ; rm reader3.tmp)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+ @(./io1 > io1.tmp ; diff io1.tmp io1.res ; rm -f io1.tmp)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+
+
diff --git a/doc/examples/Makefile.in b/doc/examples/Makefile.in
new file mode 100644
index 0000000..7c1478f
--- /dev/null
+++ b/doc/examples/Makefile.in
@@ -0,0 +1,665 @@
+# Makefile.in generated by automake 1.8.2 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+SOURCES = $(io1_SOURCES) $(parse1_SOURCES) $(parse2_SOURCES) $(reader1_SOURCES) $(reader2_SOURCES) $(reader3_SOURCES) $(testWriter_SOURCES) $(tree1_SOURCES) $(tree2_SOURCES) $(xpath1_SOURCES)
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+top_builddir = ../..
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+INSTALL = @INSTALL@
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+host_triplet = @host@
+noinst_PROGRAMS = xpath1$(EXEEXT) parse1$(EXEEXT) parse2$(EXEEXT) \
+ tree1$(EXEEXT) tree2$(EXEEXT) testWriter$(EXEEXT) \
+ reader1$(EXEEXT) reader2$(EXEEXT) reader3$(EXEEXT) \
+ io1$(EXEEXT)
+subdir = doc/examples
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
+ $(top_srcdir)/configure.in
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+PROGRAMS = $(noinst_PROGRAMS)
+am_io1_OBJECTS = io1.$(OBJEXT)
+io1_OBJECTS = $(am_io1_OBJECTS)
+am__DEPENDENCIES_1 =
+am__DEPENDENCIES_2 = $(top_builddir)/libxml2.la $(am__DEPENDENCIES_1)
+am_parse1_OBJECTS = parse1.$(OBJEXT)
+parse1_OBJECTS = $(am_parse1_OBJECTS)
+am_parse2_OBJECTS = parse2.$(OBJEXT)
+parse2_OBJECTS = $(am_parse2_OBJECTS)
+am_reader1_OBJECTS = reader1.$(OBJEXT)
+reader1_OBJECTS = $(am_reader1_OBJECTS)
+am_reader2_OBJECTS = reader2.$(OBJEXT)
+reader2_OBJECTS = $(am_reader2_OBJECTS)
+am_reader3_OBJECTS = reader3.$(OBJEXT)
+reader3_OBJECTS = $(am_reader3_OBJECTS)
+am_testWriter_OBJECTS = testWriter.$(OBJEXT)
+testWriter_OBJECTS = $(am_testWriter_OBJECTS)
+am_tree1_OBJECTS = tree1.$(OBJEXT)
+tree1_OBJECTS = $(am_tree1_OBJECTS)
+am_tree2_OBJECTS = tree2.$(OBJEXT)
+tree2_OBJECTS = $(am_tree2_OBJECTS)
+am_xpath1_OBJECTS = xpath1.$(OBJEXT)
+xpath1_OBJECTS = $(am_xpath1_OBJECTS)
+DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/io1.Po ./$(DEPDIR)/parse1.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/parse2.Po ./$(DEPDIR)/reader1.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/reader2.Po ./$(DEPDIR)/reader3.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/testWriter.Po ./$(DEPDIR)/tree1.Po \
+@AMDEP_TRUE@ ./$(DEPDIR)/tree2.Po ./$(DEPDIR)/xpath1.Po
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+SOURCES = $(io1_SOURCES) $(parse1_SOURCES) $(parse2_SOURCES) \
+ $(reader1_SOURCES) $(reader2_SOURCES) $(reader3_SOURCES) \
+ $(testWriter_SOURCES) $(tree1_SOURCES) $(tree2_SOURCES) \
+ $(xpath1_SOURCES)
+DIST_SOURCES = $(io1_SOURCES) $(parse1_SOURCES) $(parse2_SOURCES) \
+ $(reader1_SOURCES) $(reader2_SOURCES) $(reader3_SOURCES) \
+ $(testWriter_SOURCES) $(tree1_SOURCES) $(tree2_SOURCES) \
+ $(xpath1_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMDEP_FALSE = @AMDEP_FALSE@
+AMDEP_TRUE = @AMDEP_TRUE@
+AMTAR = @AMTAR@
+AR = @AR@
+AS = @AS@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+C14N_OBJ = @C14N_OBJ@
+CATALOG_OBJ = @CATALOG_OBJ@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEBUG_OBJ = @DEBUG_OBJ@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DOCB_OBJ = @DOCB_OBJ@
+ECHO = @ECHO@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+F77 = @F77@
+FFLAGS = @FFLAGS@
+FTP_OBJ = @FTP_OBJ@
+HAVE_ISINF = @HAVE_ISINF@
+HAVE_ISNAN = @HAVE_ISNAN@
+HTML_DIR = @HTML_DIR@
+HTML_OBJ = @HTML_OBJ@
+HTTP_OBJ = @HTTP_OBJ@
+ICONV_LIBS = @ICONV_LIBS@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIBXML_MAJOR_VERSION = @LIBXML_MAJOR_VERSION@
+LIBXML_MICRO_VERSION = @LIBXML_MICRO_VERSION@
+LIBXML_MINOR_VERSION = @LIBXML_MINOR_VERSION@
+LIBXML_VERSION = @LIBXML_VERSION@
+LIBXML_VERSION_INFO = @LIBXML_VERSION_INFO@
+LIBXML_VERSION_NUMBER = @LIBXML_VERSION_NUMBER@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MV = @MV@
+M_LIBS = @M_LIBS@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PATTERN_TEST = @PATTERN_TEST@
+PYTHON = @PYTHON@
+PYTHON_INCLUDES = @PYTHON_INCLUDES@
+PYTHON_SITE_PACKAGES = @PYTHON_SITE_PACKAGES@
+PYTHON_SUBDIR = @PYTHON_SUBDIR@
+PYTHON_TESTS = @PYTHON_TESTS@
+PYTHON_VERSION = @PYTHON_VERSION@
+RANLIB = @RANLIB@
+RDL_LIBS = @RDL_LIBS@
+READER_TEST = @READER_TEST@
+RELDATE = @RELDATE@
+RM = @RM@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STATIC_BINARIES = @STATIC_BINARIES@
+STRIP = @STRIP@
+TAR = @TAR@
+TEST_C14N = @TEST_C14N@
+TEST_CATALOG = @TEST_CATALOG@
+TEST_DEBUG = @TEST_DEBUG@
+TEST_HTML = @TEST_HTML@
+TEST_PHTML = @TEST_PHTML@
+TEST_PUSH = @TEST_PUSH@
+TEST_REGEXPS = @TEST_REGEXPS@
+TEST_SAX = @TEST_SAX@
+TEST_SCHEMAS = @TEST_SCHEMAS@
+TEST_THREADS = @TEST_THREADS@
+TEST_VALID = @TEST_VALID@
+TEST_VTIME = @TEST_VTIME@
+TEST_XINCLUDE = @TEST_XINCLUDE@
+TEST_XPATH = @TEST_XPATH@
+TEST_XPTR = @TEST_XPTR@
+THREADS_W32 = @THREADS_W32@
+THREAD_CFLAGS = @THREAD_CFLAGS@
+THREAD_LIBS = @THREAD_LIBS@
+U = @U@
+VERSION = @VERSION@
+WIN32_EXTRA_LDFLAGS = @WIN32_EXTRA_LDFLAGS@
+WIN32_EXTRA_LIBADD = @WIN32_EXTRA_LIBADD@
+WITH_C14N = @WITH_C14N@
+WITH_CATALOG = @WITH_CATALOG@
+WITH_DEBUG = @WITH_DEBUG@
+WITH_DOCB = @WITH_DOCB@
+WITH_FTP = @WITH_FTP@
+WITH_HTML = @WITH_HTML@
+WITH_HTTP = @WITH_HTTP@
+WITH_ICONV = @WITH_ICONV@
+WITH_ISO8859X = @WITH_ISO8859X@
+WITH_LEGACY = @WITH_LEGACY@
+WITH_MEM_DEBUG = @WITH_MEM_DEBUG@
+WITH_OUTPUT = @WITH_OUTPUT@
+WITH_PATTERN = @WITH_PATTERN@
+WITH_PUSH = @WITH_PUSH@
+WITH_PYTHON_FALSE = @WITH_PYTHON_FALSE@
+WITH_PYTHON_TRUE = @WITH_PYTHON_TRUE@
+WITH_READER = @WITH_READER@
+WITH_REGEXPS = @WITH_REGEXPS@
+WITH_SAX1 = @WITH_SAX1@
+WITH_SCHEMAS = @WITH_SCHEMAS@
+WITH_THREADS = @WITH_THREADS@
+WITH_TREE = @WITH_TREE@
+WITH_TRIO = @WITH_TRIO@
+WITH_TRIO_SOURCES_FALSE = @WITH_TRIO_SOURCES_FALSE@
+WITH_TRIO_SOURCES_TRUE = @WITH_TRIO_SOURCES_TRUE@
+WITH_VALID = @WITH_VALID@
+WITH_WRITER = @WITH_WRITER@
+WITH_XINCLUDE = @WITH_XINCLUDE@
+WITH_XPATH = @WITH_XPATH@
+WITH_XPTR = @WITH_XPTR@
+XINCLUDE_OBJ = @XINCLUDE_OBJ@
+XML_CFLAGS = @XML_CFLAGS@
+XML_INCLUDEDIR = @XML_INCLUDEDIR@
+XML_LIBDIR = @XML_LIBDIR@
+XML_LIBS = @XML_LIBS@
+XML_LIBTOOLLIBS = @XML_LIBTOOLLIBS@
+XPATH_OBJ = @XPATH_OBJ@
+XPTR_OBJ = @XPTR_OBJ@
+Z_CFLAGS = @Z_CFLAGS@
+Z_LIBS = @Z_LIBS@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_AS = @ac_ct_AS@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_DLLTOOL = @ac_ct_DLLTOOL@
+ac_ct_F77 = @ac_ct_F77@
+ac_ct_OBJDUMP = @ac_ct_OBJDUMP@
+ac_ct_RANLIB = @ac_ct_RANLIB@
+ac_ct_STRIP = @ac_ct_STRIP@
+am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
+am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
+am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
+am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+datadir = @datadir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+pythondir = @pythondir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+
+# Beware this is autogenerated by index.py
+INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I@srcdir@/include @THREAD_CFLAGS@ @Z_CFLAGS@
+DEPS = $(top_builddir)/libxml2.la
+LDADDS = @STATIC_BINARIES@ $(top_builddir)/libxml2.la @THREAD_LIBS@ @Z_LIBS@ $(ICONV_LIBS) -lm @WIN32_EXTRA_LIBADD@
+EXTRA_DIST = examples.xsl index.py test1.xml examples.xml test2.xml writer.xml test3.xml reader1.res reader3.res tree1.res tree2.res io1.res
+xpath1_SOURCES = xpath1.c
+xpath1_LDFLAGS =
+xpath1_DEPENDENCIES = $(DEPS)
+xpath1_LDADD = @RDL_LIBS@ $(LDADDS)
+parse1_SOURCES = parse1.c
+parse1_LDFLAGS =
+parse1_DEPENDENCIES = $(DEPS)
+parse1_LDADD = @RDL_LIBS@ $(LDADDS)
+parse2_SOURCES = parse2.c
+parse2_LDFLAGS =
+parse2_DEPENDENCIES = $(DEPS)
+parse2_LDADD = @RDL_LIBS@ $(LDADDS)
+tree1_SOURCES = tree1.c
+tree1_LDFLAGS =
+tree1_DEPENDENCIES = $(DEPS)
+tree1_LDADD = @RDL_LIBS@ $(LDADDS)
+tree2_SOURCES = tree2.c
+tree2_LDFLAGS =
+tree2_DEPENDENCIES = $(DEPS)
+tree2_LDADD = @RDL_LIBS@ $(LDADDS)
+testWriter_SOURCES = testWriter.c
+testWriter_LDFLAGS =
+testWriter_DEPENDENCIES = $(DEPS)
+testWriter_LDADD = @RDL_LIBS@ $(LDADDS)
+reader1_SOURCES = reader1.c
+reader1_LDFLAGS =
+reader1_DEPENDENCIES = $(DEPS)
+reader1_LDADD = @RDL_LIBS@ $(LDADDS)
+reader2_SOURCES = reader2.c
+reader2_LDFLAGS =
+reader2_DEPENDENCIES = $(DEPS)
+reader2_LDADD = @RDL_LIBS@ $(LDADDS)
+reader3_SOURCES = reader3.c
+reader3_LDFLAGS =
+reader3_DEPENDENCIES = $(DEPS)
+reader3_LDADD = @RDL_LIBS@ $(LDADDS)
+io1_SOURCES = io1.c
+io1_LDFLAGS =
+io1_DEPENDENCIES = $(DEPS)
+io1_LDADD = @RDL_LIBS@ $(LDADDS)
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
+ && exit 0; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu doc/examples/Makefile'; \
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --gnu doc/examples/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+clean-noinstPROGRAMS:
+ @list='$(noinst_PROGRAMS)'; for p in $$list; do \
+ f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
+ echo " rm -f $$p $$f"; \
+ rm -f $$p $$f ; \
+ done
+io1$(EXEEXT): $(io1_OBJECTS) $(io1_DEPENDENCIES)
+ @rm -f io1$(EXEEXT)
+ $(LINK) $(io1_LDFLAGS) $(io1_OBJECTS) $(io1_LDADD) $(LIBS)
+parse1$(EXEEXT): $(parse1_OBJECTS) $(parse1_DEPENDENCIES)
+ @rm -f parse1$(EXEEXT)
+ $(LINK) $(parse1_LDFLAGS) $(parse1_OBJECTS) $(parse1_LDADD) $(LIBS)
+parse2$(EXEEXT): $(parse2_OBJECTS) $(parse2_DEPENDENCIES)
+ @rm -f parse2$(EXEEXT)
+ $(LINK) $(parse2_LDFLAGS) $(parse2_OBJECTS) $(parse2_LDADD) $(LIBS)
+reader1$(EXEEXT): $(reader1_OBJECTS) $(reader1_DEPENDENCIES)
+ @rm -f reader1$(EXEEXT)
+ $(LINK) $(reader1_LDFLAGS) $(reader1_OBJECTS) $(reader1_LDADD) $(LIBS)
+reader2$(EXEEXT): $(reader2_OBJECTS) $(reader2_DEPENDENCIES)
+ @rm -f reader2$(EXEEXT)
+ $(LINK) $(reader2_LDFLAGS) $(reader2_OBJECTS) $(reader2_LDADD) $(LIBS)
+reader3$(EXEEXT): $(reader3_OBJECTS) $(reader3_DEPENDENCIES)
+ @rm -f reader3$(EXEEXT)
+ $(LINK) $(reader3_LDFLAGS) $(reader3_OBJECTS) $(reader3_LDADD) $(LIBS)
+testWriter$(EXEEXT): $(testWriter_OBJECTS) $(testWriter_DEPENDENCIES)
+ @rm -f testWriter$(EXEEXT)
+ $(LINK) $(testWriter_LDFLAGS) $(testWriter_OBJECTS) $(testWriter_LDADD) $(LIBS)
+tree1$(EXEEXT): $(tree1_OBJECTS) $(tree1_DEPENDENCIES)
+ @rm -f tree1$(EXEEXT)
+ $(LINK) $(tree1_LDFLAGS) $(tree1_OBJECTS) $(tree1_LDADD) $(LIBS)
+tree2$(EXEEXT): $(tree2_OBJECTS) $(tree2_DEPENDENCIES)
+ @rm -f tree2$(EXEEXT)
+ $(LINK) $(tree2_LDFLAGS) $(tree2_OBJECTS) $(tree2_LDADD) $(LIBS)
+xpath1$(EXEEXT): $(xpath1_OBJECTS) $(xpath1_DEPENDENCIES)
+ @rm -f xpath1$(EXEEXT)
+ $(LINK) $(xpath1_LDFLAGS) $(xpath1_OBJECTS) $(xpath1_LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/io1.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parse1.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parse2.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reader1.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reader2.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reader3.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testWriter.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tree1.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tree2.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xpath1.Po@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Plo' tmpdepfile='$(DEPDIR)/$*.TPlo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+distclean-libtool:
+ -rm -f libtool
+uninstall-info-am:
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ test -z "$(ETAGS_ARGS)$$tags$$unique" \
+ || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$tags $$unique
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ test -z "$(CTAGS_ARGS)$$tags$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$tags $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && cd $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
+ list='$(DISTFILES)'; for file in $$list; do \
+ case $$file in \
+ $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
+ $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
+ esac; \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test "$$dir" != "$$file" && test "$$dir" != "."; then \
+ dir="/$$dir"; \
+ $(mkdir_p) "$(distdir)$$dir"; \
+ else \
+ dir=''; \
+ fi; \
+ if test -d $$d/$$file; then \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+ fi; \
+ cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(PROGRAMS)
+installdirs:
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -rm -f $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \
+ mostlyclean-am
+
+distclean: distclean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-libtool distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+info: info-am
+
+info-am:
+
+install-data-am: install-data-local
+
+install-exec-am:
+
+install-info: install-info-am
+
+install-man:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-info-am
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+ clean-libtool clean-noinstPROGRAMS ctags distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-tags distdir dvi dvi-am html html-am info info-am \
+ install install-am install-data install-data-am \
+ install-data-local install-exec install-exec-am install-info \
+ install-info-am install-man install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags uninstall uninstall-am uninstall-info-am
+
+
+rebuild: examples.xml index.html
+
+examples.xml: index.py *.c
+ -@($(srcdir)/index.py)
+
+index.html: examples.xml examples.xsl
+ -@(xsltproc examples.xsl examples.xml && echo "Rebuilt web page" && xmllint --valid --noout index.html)
+
+install-data-local:
+ $(mkinstalldirs) $(DESTDIR)$(HTML_DIR)
+ -@INSTALL@ -m 0644 $(srcdir)/*.html $(srcdir)/*.c $(srcdir)/*.xml $(srcdir)/*.xsl $(srcdir)/*.res $(DESTDIR)$(HTML_DIR)
+
+tests: $(noinst_PROGRAMS)
+ @(echo > .memdump)
+ @(./parse1 test1.xml)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+ @(./parse2 test2.xml)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+ @(./tree1 test2.xml > tree1.tmp ; diff tree1.tmp tree1.res ; rm tree1.tmp)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+ @(./tree2 > tree2.tmp ; diff tree2.tmp tree2.res ; rm tree2.tmp)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+ @(./testWriter ; for i in 1 2 3 4 ; do diff writer.xml writer$$i.res ; done ; rm writer*.res)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+ @(./reader1 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+ @(./reader2 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+ @(./reader3 > reader3.tmp ; diff reader3.tmp reader3.res ; rm reader3.tmp)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+ @(./io1 > io1.tmp ; diff io1.tmp io1.res ; rm -f io1.tmp)
+ @(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/doc/examples/examples.xml b/doc/examples/examples.xml
new file mode 100644
index 0000000..9c14221
--- /dev/null
+++ b/doc/examples/examples.xml
@@ -0,0 +1,602 @@
+<examples>
+ <example filename='xpath1.c'>
+ <synopsis>Evaluate XPath expression and prints result node set.</synopsis>
+ <purpose>Shows how to evaluate XPath expression and register known namespaces in XPath context.</purpose>
+ <usage>xpath1 &lt;xml-file&gt; &lt;xpath-expr&gt; [&lt;known-ns-list&gt;]</usage>
+ <author>Aleksey Sanin</author>
+ <copy>see Copyright for the status of this software. </copy>
+ <section>XPath</section>
+ <includes>
+ <include>&lt;libxml/xpath.h&gt;</include>
+ <include>&lt;libxml/parser.h&gt;</include>
+ <include>&lt;libxml/xpathInternals.h&gt;</include>
+ <include>&lt;libxml/tree.h&gt;</include>
+ </includes>
+ <uses>
+ <enum line='228' file='tree' name='XML_ELEMENT_NODE'/>
+ <typedef line='87' file='xpath' name='xmlXPathObjectPtr'/>
+ <function line='53' file='xmlmemory' name='xmlMemoryDump'/>
+ <function line='116' file='xpath' name='xmlXPathEvalExpression'/>
+ <function line='185' file='xpathInternals' name='xmlXPathRegisterNs'/>
+ <function line='128' file='xpath' name='xmlXPathFreeObject'/>
+ <typedef line='85' file='tree' name='xmlDocPtr'/>
+ <typedef line='217' file='tree' name='xmlNsPtr'/>
+ <function line='100' file='xpath' name='xmlXPathNewContext'/>
+ <typedef line='205' file='tree' name='xmlNodePtr'/>
+ <function line='48' file='parser' name='xmlCleanupParser'/>
+ <macro line='42' file='xmlversion' name='LIBXML_TEST_VERSION'/>
+ <typedef line='86' file='xpath' name='xmlXPathContextPtr'/>
+ <function line='129' file='xpath' name='xmlXPathFreeContext'/>
+ <function line='38' file='parser' name='xmlInitParser'/>
+ <function line='155' file='xmlstring' name='xmlStrdup'/>
+ <function line='130' file='tree' name='xmlFreeDoc'/>
+ <function line='179' file='xmlstring' name='xmlStrchr'/>
+ <variable line='192' file='globals' name='xmlFree'/>
+ <function line='93' file='parser' name='xmlParseFile'/>
+ <enum line='216' file='tree' name='XML_NAMESPACE_DECL'/>
+ </uses>
+ </example>
+ <example filename='parse1.c'>
+ <synopsis>Parse an XML file to a tree and free it</synopsis>
+ <purpose>Demonstrate the use of xmlReadFile() to read an XML file into a tree and and xmlFreeDoc() to free the resulting tree</purpose>
+ <usage>parse1 test1.xml</usage>
+ <test>parse1 test1.xml</test>
+ <author>Daniel Veillard</author>
+ <copy>see Copyright for the status of this software. </copy>
+ <section>Parsing</section>
+ <includes>
+ <include>&lt;libxml/tree.h&gt;</include>
+ <include>&lt;libxml/parser.h&gt;</include>
+ </includes>
+ <uses>
+ <function line='50' file='parser' name='xmlCleanupParser'/>
+ <macro line='45' file='xmlversion' name='LIBXML_TEST_VERSION'/>
+ <typedef line='24' file='tree' name='xmlDocPtr'/>
+ <function line='31' file='tree' name='xmlFreeDoc'/>
+ <function line='26' file='parser' name='xmlReadFile'/>
+ <function line='54' file='xmlmemory' name='xmlMemoryDump'/>
+ </uses>
+ </example>
+ <example filename='parse2.c'>
+ <synopsis>Parse and validate an XML file to a tree and free the result</synopsis>
+ <purpose>Create a parser context for an XML file, then parse and validate the file, creating a tree, check the validation result and xmlFreeDoc() to free the resulting tree.</purpose>
+ <usage>parse2 test2.xml</usage>
+ <test>parse2 test2.xml</test>
+ <author>Daniel Veillard</author>
+ <copy>see Copyright for the status of this software. </copy>
+ <section>Parsing</section>
+ <includes>
+ <include>&lt;libxml/tree.h&gt;</include>
+ <include>&lt;libxml/parser.h&gt;</include>
+ </includes>
+ <uses>
+ <function line='47' file='parser' name='xmlFreeParserCtxt'/>
+ <macro line='61' file='xmlversion' name='LIBXML_TEST_VERSION'/>
+ <enum line='35' file='parser' name='XML_PARSE_DTDVALID'/>
+ <function line='29' file='parser' name='xmlNewParserCtxt'/>
+ <function line='66' file='parser' name='xmlCleanupParser'/>
+ <typedef line='25' file='tree' name='xmlParserCtxtPtr'/>
+ <function line='35' file='parser' name='xmlCtxtReadFile'/>
+ <function line='44' file='tree' name='xmlFreeDoc'/>
+ <typedef line='26' file='tree' name='xmlDocPtr'/>
+ <function line='70' file='xmlmemory' name='xmlMemoryDump'/>
+ </uses>
+ </example>
+ <example filename='tree1.c'>
+ <synopsis>Navigates a tree to print element names</synopsis>
+ <purpose>Parse a file to a tree, use xmlDocGetRootElement() to get the root element, then walk the document and print all the element name in document order.</purpose>
+ <usage>tree1 filename_or_URL</usage>
+ <test>tree1 test2.xml &gt; tree1.tmp ; diff tree1.tmp tree1.res ; rm tree1.tmp</test>
+ <author>Dodji Seketeli</author>
+ <copy>see Copyright for the status of this software. </copy>
+ <section>Tree</section>
+ <includes>
+ <include>&lt;libxml/tree.h&gt;</include>
+ <include>&lt;libxml/parser.h&gt;</include>
+ </includes>
+ <uses>
+ <function line='85' file='parser' name='xmlCleanupParser'/>
+ <macro line='67' file='xmlversion' name='LIBXML_TEST_VERSION'/>
+ <enum line='36' file='tree' name='XML_ELEMENT_NODE'/>
+ <function line='79' file='tree' name='xmlFreeDoc'/>
+ <function line='67' file='parser' name='xmlParseFile'/>
+ <function line='74' file='tree' name='xmlDocGetRootElement'/>
+ </uses>
+ </example>
+ <example filename='tree2.c'>
+ <synopsis>Creates a tree</synopsis>
+ <purpose>Shows how to create document, nodes and dump it to stdout or file.</purpose>
+ <usage>tree2 &lt;filename&gt; -Default output: stdout</usage>
+ <test>tree2 &gt; tree2.tmp ; diff tree2.tmp tree2.res ; rm tree2.tmp</test>
+ <author>Lucas Brasilino &lt;brasilino@recife.pe.gov.br&gt;</author>
+ <copy>see Copyright for the status of this software </copy>
+ <section>Tree</section>
+ <includes>
+ <include>&lt;libxml/tree.h&gt;</include>
+ <include>&lt;libxml/parser.h&gt;</include>
+ </includes>
+ <uses>
+ <function line='75' file='tree' name='xmlNewText'/>
+ <function line='110' file='xmlmemory' name='xmlMemoryDump'/>
+ <function line='96' file='tree' name='xmlSaveFormatFileEnc'/>
+ <function line='78' file='tree' name='xmlAddChild'/>
+ <function line='41' file='tree' name='xmlDocSetRootElement'/>
+ <function line='105' file='parser' name='xmlCleanupParser'/>
+ <macro line='34' file='xmlversion' name='LIBXML_TEST_VERSION'/>
+ <function line='89' file='tree' name='xmlNewProp'/>
+ <function line='88' file='tree' name='xmlNewChild'/>
+ <function line='74' file='tree' name='xmlNewNode'/>
+ <function line='46' file='tree' name='xmlCreateIntSubset'/>
+ <function line='99' file='tree' name='xmlFreeDoc'/>
+ <function line='39' file='tree' name='xmlNewDoc'/>
+ </uses>
+ </example>
+ <example filename='testWriter.c'>
+ <synopsis>use various APIs for the xmlWriter</synopsis>
+ <purpose>tests a number of APIs for the xmlWriter, especially the various methods to write to a filename, to a memory buffer, to a new document, or to a subtree. It shows how to do encoding string conversions too. The resulting documents are then serialized.</purpose>
+ <usage>testWriter</usage>
+ <test>testWriter ; for i in 1 2 3 4 ; do diff writer.xml writer$$i.res ; done ; rm writer*.res</test>
+ <author>Alfred Mickautsch</author>
+ <copy>see Copyright for the status of this software. </copy>
+ <section>xmlWriter</section>
+ <includes>
+ <include>&lt;libxml/encoding.h&gt;</include>
+ <include>&lt;libxml/xmlwriter.h&gt;</include>
+ </includes>
+ <uses>
+ <function line='1111' file='xmlwriter' name='xmlTextWriterEndElement'/>
+ <function line='901' file='tree' name='xmlDocSetRootElement'/>
+ <function line='913' file='xmlwriter' name='xmlTextWriterStartDocument'/>
+ <function line='1121' file='xmlwriter' name='xmlTextWriterEndDocument'/>
+ <function line='959' file='xmlwriter' name='xmlTextWriterWriteFormatComment'/>
+ <function line='925' file='xmlwriter' name='xmlTextWriterWriteComment'/>
+ <function line='54' file='parser' name='xmlCleanupParser'/>
+ <variable line='1166' file='globals' name='xmlMalloc'/>
+ <function line='1073' file='xmlwriter' name='xmlTextWriterWriteFormatElement'/>
+ <function line='1156' file='encoding' name='xmlFindCharEncodingHandler'/>
+ <typedef line='1151' file='encoding' name='xmlCharEncodingHandlerPtr'/>
+ <function line='904' file='xmlwriter' name='xmlNewTextWriterTree'/>
+ <function line='76' file='xmlwriter' name='xmlNewTextWriterFilename'/>
+ <function line='1131' file='tree' name='xmlFreeDoc'/>
+ <typedef line='880' file='tree' name='xmlNodePtr'/>
+ <typedef line='879' file='tree' name='xmlDocPtr'/>
+ <typedef line='341' file='tree' name='xmlBufferPtr'/>
+ <function line='632' file='xmlwriter' name='xmlNewTextWriterDoc'/>
+ <function line='894' file='tree' name='xmlNewDocNode'/>
+ <function line='1129' file='tree' name='xmlSaveFileEnc'/>
+ <function line='58' file='xmlmemory' name='xmlMemoryDump'/>
+ <macro line='885' file='parser' name='XML_DEFAULT_VERSION'/>
+ <function line='355' file='xmlwriter' name='xmlNewTextWriterMemory'/>
+ <variable line='1180' file='globals' name='xmlFree'/>
+ <function line='1096' file='xmlwriter' name='xmlTextWriterStartElement'/>
+ <function line='1127' file='xmlwriter' name='xmlFreeTextWriter'/>
+ <function line='347' file='tree' name='xmlBufferCreate'/>
+ <macro line='40' file='xmlversion' name='LIBXML_TEST_VERSION'/>
+ <function line='613' file='tree' name='xmlBufferFree'/>
+ <typedef line='878' file='xmlwriter' name='xmlTextWriterPtr'/>
+ <function line='1103' file='xmlwriter' name='xmlTextWriterWriteElement'/>
+ <function line='949' file='xmlwriter' name='xmlTextWriterWriteAttribute'/>
+ <variable line='1183' file='globals' name='xmlRealloc'/>
+ <function line='885' file='tree' name='xmlNewDoc'/>
+ </uses>
+ </example>
+ <example filename='reader1.c'>
+ <synopsis>Parse an XML file with an xmlReader</synopsis>
+ <purpose>Demonstrate the use of xmlReaderForFile() to parse an XML file and dump the informations about the nodes found in the process. (Note that the XMLReader functions require libxml2 version later than 2.6.)</purpose>
+ <usage>reader1 &lt;filename&gt;</usage>
+ <test>reader1 test2.xml &gt; reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp</test>
+ <author>Daniel Veillard</author>
+ <copy>see Copyright for the status of this software. </copy>
+ <section>xmlReader</section>
+ <includes>
+ <include>&lt;libxml/xmlreader.h&gt;</include>
+ </includes>
+ <uses>
+ <function line='44' file='xmlstring' name='xmlStrlen'/>
+ <function line='37' file='xmlreader' name='xmlTextReaderNodeType'/>
+ <typedef line='59' file='xmlreader' name='xmlTextReaderPtr'/>
+ <function line='98' file='xmlmemory' name='xmlMemoryDump'/>
+ <function line='33' file='xmlreader' name='xmlTextReaderConstValue'/>
+ <function line='36' file='xmlreader' name='xmlTextReaderDepth'/>
+ <function line='69' file='xmlreader' name='xmlFreeTextReader'/>
+ <function line='29' file='xmlreader' name='xmlTextReaderConstName'/>
+ <function line='40' file='xmlreader' name='xmlTextReaderHasValue'/>
+ <function line='67' file='xmlreader' name='xmlTextReaderRead'/>
+ <function line='39' file='xmlreader' name='xmlTextReaderIsEmptyElement'/>
+ <function line='62' file='xmlreader' name='xmlReaderForFile'/>
+ </uses>
+ </example>
+ <example filename='reader2.c'>
+ <synopsis>Parse and validate an XML file with an xmlReader</synopsis>
+ <purpose>Demonstrate the use of xmlReaderForFile() to parse an XML file validating the content in the process and activating options like entities substitution, and DTD attributes defaulting. (Note that the XMLReader functions require libxml2 version later than 2.6.)</purpose>
+ <usage>reader2 &lt;valid_xml_filename&gt;</usage>
+ <test>reader2 test2.xml &gt; reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp</test>
+ <author>Daniel Veillard</author>
+ <copy>see Copyright for the status of this software. </copy>
+ <section>xmlReader</section>
+ <includes>
+ <include>&lt;libxml/xmlreader.h&gt;</include>
+ </includes>
+ <uses>
+ <function line='45' file='xmlstring' name='xmlStrlen'/>
+ <function line='38' file='xmlreader' name='xmlTextReaderNodeType'/>
+ <typedef line='60' file='xmlreader' name='xmlTextReaderPtr'/>
+ <function line='34' file='xmlreader' name='xmlTextReaderConstValue'/>
+ <enum line='70' file='parser' name='XML_PARSE_NOENT'/>
+ <function line='37' file='xmlreader' name='xmlTextReaderDepth'/>
+ <enum line='71' file='parser' name='XML_PARSE_DTDVALID'/>
+ <enum line='69' file='parser' name='XML_PARSE_DTDATTR'/>
+ <function line='84' file='xmlreader' name='xmlFreeTextReader'/>
+ <function line='30' file='xmlreader' name='xmlTextReaderConstName'/>
+ <function line='41' file='xmlreader' name='xmlTextReaderHasValue'/>
+ <function line='76' file='xmlreader' name='xmlTextReaderRead'/>
+ <function line='40' file='xmlreader' name='xmlTextReaderIsEmptyElement'/>
+ <function line='68' file='xmlreader' name='xmlReaderForFile'/>
+ <function line='81' file='xmlreader' name='xmlTextReaderIsValid'/>
+ </uses>
+ </example>
+ <example filename='reader3.c'>
+ <synopsis>Show how to extract subdocuments with xmlReader</synopsis>
+ <purpose>Demonstrate the use of xmlTextReaderPreservePattern() to parse an XML file with the xmlReader while collecting only some subparts of the document. (Note that the XMLReader functions require libxml2 version later than 2.6.)</purpose>
+ <usage>reader3</usage>
+ <test>reader3 &gt; reader3.tmp ; diff reader3.tmp reader3.res ; rm reader3.tmp</test>
+ <author>Daniel Veillard</author>
+ <copy>see Copyright for the status of this software. </copy>
+ <section>xmlReader</section>
+ <includes>
+ <include>&lt;libxml/xmlreader.h&gt;</include>
+ </includes>
+ <uses>
+ <typedef line='31' file='xmlreader' name='xmlTextReaderPtr'/>
+ <function line='37' file='xmlreader' name='xmlReaderForFile'/>
+ <function line='65' file='xmlreader' name='xmlFreeTextReader'/>
+ <function line='95' file='tree' name='xmlDocDump'/>
+ <function line='51' file='xmlreader' name='xmlTextReaderRead'/>
+ <function line='61' file='xmlreader' name='xmlTextReaderCurrentDoc'/>
+ <function line='42' file='xmlreader' name='xmlTextReaderPreservePattern'/>
+ <typedef line='76' file='tree' name='xmlDocPtr'/>
+ </uses>
+ </example>
+ <example filename='io1.c'>
+ <synopsis>Example of custom Input/Output</synopsis>
+ <purpose>Demonstrate the use of xmlRegisterInputCallbacks to build a custom I/O layer, this is used in an XInclude method context to show how dynamic document can be built in a clean way.</purpose>
+ <usage>io1</usage>
+ <test>io1 &gt; io1.tmp ; diff io1.tmp io1.res ; rm -f io1.tmp</test>
+ <author>Daniel Veillard</author>
+ <copy>see Copyright for the status of this software. </copy>
+ <section>InputOutput</section>
+ <includes>
+ <include>&lt;libxml/parser.h&gt;</include>
+ <include>&lt;libxml/xinclude.h&gt;</include>
+ <include>&lt;libxml/tree.h&gt;</include>
+ <include>&lt;libxml/xmlIO.h&gt;</include>
+ </includes>
+ <uses>
+ <function line='143' file='tree' name='xmlDocDump'/>
+ <function line='134' file='xinclude' name='xmlXIncludeProcess'/>
+ <function line='117' file='xmlIO' name='xmlRegisterInputCallbacks'/>
+ <function line='124' file='parser' name='xmlReadMemory'/>
+ <typedef line='105' file='tree' name='xmlDocPtr'/>
+ </uses>
+ </example>
+ <symbols>
+ <symbol name='LIBXML_TEST_VERSION'>
+ <ref filename='xpath1.c'/>
+ <ref filename='parse1.c'/>
+ <ref filename='parse2.c'/>
+ <ref filename='tree1.c'/>
+ <ref filename='tree2.c'/>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='XML_DEFAULT_VERSION'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='XML_ELEMENT_NODE'>
+ <ref filename='xpath1.c'/>
+ <ref filename='tree1.c'/>
+ </symbol>
+ <symbol name='XML_NAMESPACE_DECL'>
+ <ref filename='xpath1.c'/>
+ </symbol>
+ <symbol name='XML_PARSE_DTDATTR'>
+ <ref filename='reader2.c'/>
+ </symbol>
+ <symbol name='XML_PARSE_DTDVALID'>
+ <ref filename='parse2.c'/>
+ <ref filename='reader2.c'/>
+ </symbol>
+ <symbol name='XML_PARSE_NOENT'>
+ <ref filename='reader2.c'/>
+ </symbol>
+ <symbol name='xmlAddChild'>
+ <ref filename='tree2.c'/>
+ </symbol>
+ <symbol name='xmlBufferCreate'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlBufferFree'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlBufferPtr'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlCharEncodingHandlerPtr'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlCleanupParser'>
+ <ref filename='xpath1.c'/>
+ <ref filename='parse1.c'/>
+ <ref filename='parse2.c'/>
+ <ref filename='tree1.c'/>
+ <ref filename='tree2.c'/>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlCreateIntSubset'>
+ <ref filename='tree2.c'/>
+ </symbol>
+ <symbol name='xmlCtxtReadFile'>
+ <ref filename='parse2.c'/>
+ </symbol>
+ <symbol name='xmlDocDump'>
+ <ref filename='reader3.c'/>
+ <ref filename='io1.c'/>
+ </symbol>
+ <symbol name='xmlDocGetRootElement'>
+ <ref filename='tree1.c'/>
+ </symbol>
+ <symbol name='xmlDocPtr'>
+ <ref filename='xpath1.c'/>
+ <ref filename='parse1.c'/>
+ <ref filename='parse2.c'/>
+ <ref filename='testWriter.c'/>
+ <ref filename='reader3.c'/>
+ <ref filename='io1.c'/>
+ </symbol>
+ <symbol name='xmlDocSetRootElement'>
+ <ref filename='tree2.c'/>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlFindCharEncodingHandler'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlFree'>
+ <ref filename='xpath1.c'/>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlFreeDoc'>
+ <ref filename='xpath1.c'/>
+ <ref filename='parse1.c'/>
+ <ref filename='parse2.c'/>
+ <ref filename='tree1.c'/>
+ <ref filename='tree2.c'/>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlFreeParserCtxt'>
+ <ref filename='parse2.c'/>
+ </symbol>
+ <symbol name='xmlFreeTextReader'>
+ <ref filename='reader1.c'/>
+ <ref filename='reader2.c'/>
+ <ref filename='reader3.c'/>
+ </symbol>
+ <symbol name='xmlFreeTextWriter'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlInitParser'>
+ <ref filename='xpath1.c'/>
+ </symbol>
+ <symbol name='xmlMalloc'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlMemoryDump'>
+ <ref filename='xpath1.c'/>
+ <ref filename='parse1.c'/>
+ <ref filename='parse2.c'/>
+ <ref filename='tree2.c'/>
+ <ref filename='testWriter.c'/>
+ <ref filename='reader1.c'/>
+ </symbol>
+ <symbol name='xmlNewChild'>
+ <ref filename='tree2.c'/>
+ </symbol>
+ <symbol name='xmlNewDoc'>
+ <ref filename='tree2.c'/>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlNewDocNode'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlNewNode'>
+ <ref filename='tree2.c'/>
+ </symbol>
+ <symbol name='xmlNewParserCtxt'>
+ <ref filename='parse2.c'/>
+ </symbol>
+ <symbol name='xmlNewProp'>
+ <ref filename='tree2.c'/>
+ </symbol>
+ <symbol name='xmlNewText'>
+ <ref filename='tree2.c'/>
+ </symbol>
+ <symbol name='xmlNewTextWriterDoc'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlNewTextWriterFilename'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlNewTextWriterMemory'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlNewTextWriterTree'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlNodePtr'>
+ <ref filename='xpath1.c'/>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlNsPtr'>
+ <ref filename='xpath1.c'/>
+ </symbol>
+ <symbol name='xmlParseFile'>
+ <ref filename='xpath1.c'/>
+ <ref filename='tree1.c'/>
+ </symbol>
+ <symbol name='xmlParserCtxtPtr'>
+ <ref filename='parse2.c'/>
+ </symbol>
+ <symbol name='xmlReadFile'>
+ <ref filename='parse1.c'/>
+ </symbol>
+ <symbol name='xmlReadMemory'>
+ <ref filename='io1.c'/>
+ </symbol>
+ <symbol name='xmlReaderForFile'>
+ <ref filename='reader1.c'/>
+ <ref filename='reader2.c'/>
+ <ref filename='reader3.c'/>
+ </symbol>
+ <symbol name='xmlRealloc'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlRegisterInputCallbacks'>
+ <ref filename='io1.c'/>
+ </symbol>
+ <symbol name='xmlSaveFileEnc'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlSaveFormatFileEnc'>
+ <ref filename='tree2.c'/>
+ </symbol>
+ <symbol name='xmlStrchr'>
+ <ref filename='xpath1.c'/>
+ </symbol>
+ <symbol name='xmlStrdup'>
+ <ref filename='xpath1.c'/>
+ </symbol>
+ <symbol name='xmlStrlen'>
+ <ref filename='reader1.c'/>
+ <ref filename='reader2.c'/>
+ </symbol>
+ <symbol name='xmlTextReaderConstName'>
+ <ref filename='reader1.c'/>
+ <ref filename='reader2.c'/>
+ </symbol>
+ <symbol name='xmlTextReaderConstValue'>
+ <ref filename='reader1.c'/>
+ <ref filename='reader2.c'/>
+ </symbol>
+ <symbol name='xmlTextReaderCurrentDoc'>
+ <ref filename='reader3.c'/>
+ </symbol>
+ <symbol name='xmlTextReaderDepth'>
+ <ref filename='reader1.c'/>
+ <ref filename='reader2.c'/>
+ </symbol>
+ <symbol name='xmlTextReaderHasValue'>
+ <ref filename='reader1.c'/>
+ <ref filename='reader2.c'/>
+ </symbol>
+ <symbol name='xmlTextReaderIsEmptyElement'>
+ <ref filename='reader1.c'/>
+ <ref filename='reader2.c'/>
+ </symbol>
+ <symbol name='xmlTextReaderIsValid'>
+ <ref filename='reader2.c'/>
+ </symbol>
+ <symbol name='xmlTextReaderNodeType'>
+ <ref filename='reader1.c'/>
+ <ref filename='reader2.c'/>
+ </symbol>
+ <symbol name='xmlTextReaderPreservePattern'>
+ <ref filename='reader3.c'/>
+ </symbol>
+ <symbol name='xmlTextReaderPtr'>
+ <ref filename='reader1.c'/>
+ <ref filename='reader2.c'/>
+ <ref filename='reader3.c'/>
+ </symbol>
+ <symbol name='xmlTextReaderRead'>
+ <ref filename='reader1.c'/>
+ <ref filename='reader2.c'/>
+ <ref filename='reader3.c'/>
+ </symbol>
+ <symbol name='xmlTextWriterEndDocument'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlTextWriterEndElement'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlTextWriterPtr'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlTextWriterStartDocument'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlTextWriterStartElement'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlTextWriterWriteAttribute'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlTextWriterWriteComment'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlTextWriterWriteElement'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlTextWriterWriteFormatComment'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlTextWriterWriteFormatElement'>
+ <ref filename='testWriter.c'/>
+ </symbol>
+ <symbol name='xmlXIncludeProcess'>
+ <ref filename='io1.c'/>
+ </symbol>
+ <symbol name='xmlXPathContextPtr'>
+ <ref filename='xpath1.c'/>
+ </symbol>
+ <symbol name='xmlXPathEvalExpression'>
+ <ref filename='xpath1.c'/>
+ </symbol>
+ <symbol name='xmlXPathFreeContext'>
+ <ref filename='xpath1.c'/>
+ </symbol>
+ <symbol name='xmlXPathFreeObject'>
+ <ref filename='xpath1.c'/>
+ </symbol>
+ <symbol name='xmlXPathNewContext'>
+ <ref filename='xpath1.c'/>
+ </symbol>
+ <symbol name='xmlXPathObjectPtr'>
+ <ref filename='xpath1.c'/>
+ </symbol>
+ <symbol name='xmlXPathRegisterNs'>
+ <ref filename='xpath1.c'/>
+ </symbol>
+ </symbols>
+ <sections>
+ <section name='InputOutput'>
+ <example filename='io1.c'/>
+ </section>
+ <section name='Parsing'>
+ <example filename='parse1.c'/>
+ <example filename='parse2.c'/>
+ </section>
+ <section name='Tree'>
+ <example filename='tree1.c'/>
+ <example filename='tree2.c'/>
+ </section>
+ <section name='XPath'>
+ <example filename='xpath1.c'/>
+ </section>
+ <section name='xmlReader'>
+ <example filename='reader1.c'/>
+ <example filename='reader2.c'/>
+ <example filename='reader3.c'/>
+ </section>
+ <section name='xmlWriter'>
+ <example filename='testWriter.c'/>
+ </section>
+ </sections>
+</examples>
diff --git a/doc/examples/examples.xsl b/doc/examples/examples.xsl
new file mode 100644
index 0000000..e4ccfd3
--- /dev/null
+++ b/doc/examples/examples.xsl
@@ -0,0 +1,169 @@
+<?xml version="1.0"?>
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:exsl="http://exslt.org/common"
+ extension-element-prefixes="exsl"
+ exclude-result-prefixes="exsl">
+
+ <xsl:import href="../site.xsl"/>
+
+ <xsl:variable name="href_base">../</xsl:variable>
+ <xsl:variable name="menu_name">Examples Menu</xsl:variable>
+
+ <xsl:variable name="toc">
+ <form action="../search.php"
+ enctype="application/x-www-form-urlencoded" method="get">
+ <input name="query" type="text" size="20" value=""/>
+ <input name="submit" type="submit" value="Search ..."/>
+ </form>
+ <ul><!-- style="margin-left: -1em" -->
+ <li><a href="{$href_base}index.html">Home</a></li>
+ <li><a style="font-weight:bold"
+ href="{$href_base}docs.html">Developer Menu</a></li>
+ <li><a style="font-weight:bold"
+ href="{$href_base}html/index.html">API Menu</a></li>
+ <xsl:for-each select="/examples/sections/section">
+ <li><a href="#{@name}"><xsl:value-of select="@name"/> Examples</a></li>
+ </xsl:for-each>
+ <li><a href="{$href_base}guidelines.html">XML Guidelines</a></li>
+ </ul>
+ </xsl:variable>
+
+ <xsl:template match="include">
+ <xsl:variable name="header" select="substring-before(substring-after(., '/'), '&gt;')"/>
+ <xsl:variable name="doc" select="concat('../html/libxml-', $header, 'tml')"/>
+ <li><a href="{$doc}"><xsl:value-of select="."/></a></li>
+ </xsl:template>
+
+ <xsl:template match="typedef">
+ <xsl:variable name="name" select="@name"/>
+ <xsl:variable name="header" select="concat(@file, '.h')"/>
+ <xsl:variable name="doc" select="concat('../html/libxml-', @file, '.html#', $name)"/>
+ <li> line <xsl:value-of select="@line"/>: Type <a href="{$doc}"><xsl:value-of select="$name"/></a> from <xsl:value-of select="$header"/></li>
+ </xsl:template>
+
+ <xsl:template match="function">
+ <xsl:variable name="name" select="@name"/>
+ <xsl:variable name="header" select="concat(@file, '.h')"/>
+ <xsl:variable name="doc" select="concat('../html/libxml-', @file, '.html#', $name)"/>
+ <li> line <xsl:value-of select="@line"/>: Function <a href="{$doc}"><xsl:value-of select="$name"/></a> from <xsl:value-of select="$header"/></li>
+ </xsl:template>
+
+ <xsl:template match="macro">
+ <xsl:variable name="name" select="@name"/>
+ <xsl:variable name="header" select="concat(@file, '.h')"/>
+ <xsl:variable name="doc" select="concat('../html/libxml-', @file, '.html#', $name)"/>
+ <li> line <xsl:value-of select="@line"/>: Macro <a href="{$doc}"><xsl:value-of select="$name"/></a> from <xsl:value-of select="$header"/></li>
+ </xsl:template>
+
+ <xsl:template match="example">
+ <xsl:variable name="filename" select="string(@filename)"/>
+ <h3><a name="{$filename}" href="{$filename}"><xsl:value-of select="$filename"/></a>: <xsl:value-of select="synopsis"/></h3>
+ <p><xsl:value-of select="purpose"/></p>
+ <p>Includes:</p>
+ <ul>
+ <xsl:for-each select="includes/include">
+ <xsl:apply-templates select='.'/>
+ </xsl:for-each>
+ </ul>
+ <p>Uses:</p>
+ <ul>
+ <xsl:for-each select="uses/*">
+ <xsl:sort select="@line" data-type="number"/>
+ <xsl:apply-templates select='.'/>
+ </xsl:for-each>
+ </ul>
+ <p>Usage:</p>
+ <p><xsl:value-of select="usage"/></p>
+ <p>Author: <xsl:value-of select="author"/></p>
+ </xsl:template>
+
+ <xsl:template match="section">
+ <li><p> <a href="#{@name}"><xsl:value-of select="@name"/></a> :</p>
+ <ul>
+ <xsl:for-each select="example">
+ <xsl:sort select='.'/>
+ <xsl:variable name="filename" select="@filename"/>
+ <li> <a href="#{$filename}"><xsl:value-of select="$filename"/></a>: <xsl:value-of select="/examples/example[@filename = $filename]/synopsis"/></li>
+ </xsl:for-each>
+ </ul>
+ </li>
+ </xsl:template>
+
+ <xsl:template match="sections">
+ <p> The examples are stored per section depending on the main focus
+ of the example:</p>
+ <ul>
+ <xsl:for-each select="section">
+ <xsl:sort select='.'/>
+ <xsl:apply-templates select='.'/>
+ </xsl:for-each>
+ </ul>
+ </xsl:template>
+
+ <xsl:template name="sections-list">
+ <xsl:for-each select="sections/section">
+ <xsl:variable name="section" select="@name"/>
+ <h2> <a name="{$section}"></a><xsl:value-of select="$section"/> Examples</h2>
+ <xsl:apply-templates select='/examples/example[section = $section]'/>
+ </xsl:for-each>
+ </xsl:template>
+
+ <xsl:template match="examples">
+ <xsl:variable name="title">Libxml2 set of examples</xsl:variable>
+ <xsl:document href="index.html" method="xml" encoding="ISO-8859-1"
+ doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
+ doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+ <html>
+ <head>
+ <xsl:call-template name="style"/>
+ <xsl:element name="title">
+ <xsl:value-of select="$title"/>
+ </xsl:element>
+ </head>
+ <body bgcolor="#8b7765" text="#000000" link="#000000" vlink="#000000">
+ <xsl:call-template name="titlebox">
+ <xsl:with-param name="title" select="$title"/>
+ </xsl:call-template>
+ <table border="0" cellpadding="4" cellspacing="0" width="100%" align="center">
+ <tr>
+ <td bgcolor="#8b7765">
+ <table border="0" cellspacing="0" cellpadding="2" width="100%">
+ <tr>
+ <td valign="top" width="200" bgcolor="#8b7765">
+ <xsl:call-template name="toc"/>
+ </td>
+ <td valign="top" bgcolor="#8b7765">
+ <table border="0" cellspacing="0" cellpadding="1" width="100%">
+ <tr>
+ <td>
+ <table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000">
+ <tr>
+ <td>
+ <table border="0" cellpadding="3" cellspacing="1" width="100%">
+ <tr>
+ <td bgcolor="#fffacd">
+ <xsl:apply-templates select="sections"/>
+ <xsl:call-template name="sections-list"/>
+ <p><a href="../bugs.html">Daniel Veillard</a></p>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </body>
+ </html>
+ </xsl:document>
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git a/doc/examples/index.py b/doc/examples/index.py
new file mode 100755
index 0000000..c3a85de
--- /dev/null
+++ b/doc/examples/index.py
@@ -0,0 +1,296 @@
+#!/usr/bin/python -u
+#
+# Indexes the examples and build an XML description
+#
+import string
+import glob
+import sys
+try:
+ import libxml2
+except:
+ sys.exit(1)
+sys.path.append("..")
+from apibuild import CParser, escape
+
+examples = []
+extras = ['examples.xsl', 'index.py']
+tests = []
+sections = {}
+symbols = {}
+api_dict = None
+api_doc = None
+
+def load_api():
+ global api_dict
+ global api_doc
+
+ if api_dict != None:
+ return
+ api_dict = {}
+ try:
+ print "loading ../libxml2-api.xml"
+ api_doc = libxml2.parseFile("../libxml2-api.xml")
+ except:
+ print "failed to parse ../libxml2-api.xml"
+ sys.exit(1)
+
+def find_symbol(name):
+ global api_dict
+ global api_doc
+
+ if api_doc == None:
+ load_api()
+
+ if name == None:
+ return
+ if api_dict.has_key(name):
+ return api_dict[name]
+ ctxt = api_doc.xpathNewContext()
+ res = ctxt.xpathEval("/api/symbols/*[@name = '%s']" % (name))
+ if type(res) == type([]) and len(res) >= 1:
+ if len(res) > 1:
+ print "Found %d references to %s in the API" % (len(res), name)
+ node = res[0]
+ typ = node.name
+ file = node.xpathEval("string(@file)")
+ info = node.xpathEval("string(info)")
+ else:
+ print "Reference %s not found in the API" % (name)
+ return None
+ ret = (typ, file, info)
+ api_dict[name] = ret
+ return ret
+
+def parse_top_comment(filename, comment):
+ res = {}
+ lines = string.split(comment, "\n")
+ item = None
+ for line in lines:
+ while line != "" and (line[0] == ' ' or line[0] == '\t'):
+ line = line[1:]
+ while line != "" and line[0] == '*':
+ line = line[1:]
+ while line != "" and (line[0] == ' ' or line[0] == '\t'):
+ line = line[1:]
+ try:
+ (it, line) = string.split(line, ":", 1)
+ item = it
+ while line != "" and (line[0] == ' ' or line[0] == '\t'):
+ line = line[1:]
+ if res.has_key(item):
+ res[item] = res[item] + " " + line
+ else:
+ res[item] = line
+ except:
+ if item != None:
+ if res.has_key(item):
+ res[item] = res[item] + " " + line
+ else:
+ res[item] = line
+ return res
+
+def parse(filename, output):
+ global symbols
+ global sections
+
+ parser = CParser(filename)
+ parser.collect_references()
+ idx = parser.parse()
+ info = parse_top_comment(filename, parser.top_comment)
+ output.write(" <example filename='%s'>\n" % filename)
+ try:
+ synopsis = info['synopsis']
+ output.write(" <synopsis>%s</synopsis>\n" % escape(synopsis));
+ except:
+ print "Example %s lacks a synopsis description" % (filename)
+ try:
+ purpose = info['purpose']
+ output.write(" <purpose>%s</purpose>\n" % escape(purpose));
+ except:
+ print "Example %s lacks a purpose description" % (filename)
+ try:
+ usage = info['usage']
+ output.write(" <usage>%s</usage>\n" % escape(usage));
+ except:
+ print "Example %s lacks an usage description" % (filename)
+ try:
+ test = info['test']
+ output.write(" <test>%s</test>\n" % escape(test));
+ progname=filename[0:-2]
+ command=string.replace(test, progname, './' + progname, 1)
+ tests.append(command)
+ except:
+ pass
+ try:
+ author = info['author']
+ output.write(" <author>%s</author>\n" % escape(author));
+ except:
+ print "Example %s lacks an author description" % (filename)
+ try:
+ copy = info['copy']
+ output.write(" <copy>%s</copy>\n" % escape(copy));
+ except:
+ print "Example %s lacks a copyright description" % (filename)
+ try:
+ section = info['section']
+ output.write(" <section>%s</section>\n" % escape(section));
+ if sections.has_key(section):
+ sections[section].append(filename)
+ else:
+ sections[section] = [filename]
+ except:
+ print "Example %s lacks a section description" % (filename)
+ for topic in info.keys():
+ if topic != "purpose" and topic != "usage" and \
+ topic != "author" and topic != "copy" and \
+ topic != "section" and topic != "synopsis" and topic != "test":
+ str = info[topic]
+ output.write(" <extra topic='%s'>%s</extra>\n" % (
+ escape(topic), escape(str)))
+ output.write(" <includes>\n")
+ for include in idx.includes.keys():
+ if include.find("libxml") != -1:
+ output.write(" <include>%s</include>\n" % (escape(include)))
+ output.write(" </includes>\n")
+ output.write(" <uses>\n")
+ for ref in idx.references.keys():
+ id = idx.references[ref]
+ name = id.get_name()
+ line = id.get_lineno()
+ if symbols.has_key(name):
+ sinfo = symbols[name]
+ refs = sinfo[0]
+ # gather at most 5 references per symbols
+ if refs > 5:
+ continue
+ sinfo.append(filename)
+ sinfo[0] = refs + 1
+ else:
+ symbols[name] = [1, filename]
+ info = find_symbol(name)
+ if info != None:
+ type = info[0]
+ file = info[1]
+ output.write(" <%s line='%d' file='%s' name='%s'/>\n" % (type,
+ line, file, name))
+ else:
+ type = id.get_type()
+ output.write(" <%s line='%d' name='%s'/>\n" % (type,
+ line, name))
+
+ output.write(" </uses>\n")
+ output.write(" </example>\n")
+
+ return idx
+
+def dump_symbols(output):
+ global symbols
+
+ output.write(" <symbols>\n")
+ keys = symbols.keys()
+ keys.sort()
+ for symbol in keys:
+ output.write(" <symbol name='%s'>\n" % (symbol))
+ info = symbols[symbol]
+ i = 1
+ while i < len(info):
+ output.write(" <ref filename='%s'/>\n" % (info[i]))
+ i = i + 1
+ output.write(" </symbol>\n")
+ output.write(" </symbols>\n")
+
+def dump_sections(output):
+ global sections
+
+ output.write(" <sections>\n")
+ keys = sections.keys()
+ keys.sort()
+ for section in keys:
+ output.write(" <section name='%s'>\n" % (section))
+ info = sections[section]
+ i = 0
+ while i < len(info):
+ output.write(" <example filename='%s'/>\n" % (info[i]))
+ i = i + 1
+ output.write(" </section>\n")
+ output.write(" </sections>\n")
+
+def dump_Makefile():
+ for file in glob.glob('*.xml'):
+ extras.append(file)
+ for file in glob.glob('*.res'):
+ extras.append(file)
+ Makefile="""# Beware this is autogenerated by index.py
+INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I@srcdir@/include @THREAD_CFLAGS@ @Z_CFLAGS@
+DEPS = $(top_builddir)/libxml2.la
+LDADDS = @STATIC_BINARIES@ $(top_builddir)/libxml2.la @THREAD_LIBS@ @Z_LIBS@ $(ICONV_LIBS) -lm @WIN32_EXTRA_LIBADD@
+
+rebuild: examples.xml index.html
+
+examples.xml: index.py *.c
+ -@($(srcdir)/index.py)
+
+index.html: examples.xml examples.xsl
+ -@(xsltproc examples.xsl examples.xml && echo "Rebuilt web page" && xmllint --valid --noout index.html)
+
+install-data-local:
+ $(mkinstalldirs) $(DESTDIR)$(HTML_DIR)
+ -@INSTALL@ -m 0644 $(srcdir)/*.html $(srcdir)/*.c $(srcdir)/*.xml $(srcdir)/*.xsl $(srcdir)/*.res $(DESTDIR)$(HTML_DIR)
+
+"""
+ EXTRA_DIST=""
+ for extra in extras:
+ EXTRA_DIST = EXTRA_DIST + extra + " "
+ Makefile = Makefile + "EXTRA_DIST=%s\n\n" % (EXTRA_DIST)
+ noinst_PROGRAMS=""
+ for example in examples:
+ noinst_PROGRAMS = noinst_PROGRAMS + example + " "
+ Makefile = Makefile + "noinst_PROGRAMS=%s\n\n" % (noinst_PROGRAMS)
+ for example in examples:
+ Makefile = Makefile + "%s_SOURCES=%s.c\n%s_LDFLAGS=\n%s_DEPENDENCIES= $(DEPS)\n%s_LDADD= @RDL_LIBS@ $(LDADDS)\n\n" % (example, example, example,
+ example, example)
+ Makefile = Makefile + "tests: $(noinst_PROGRAMS)\n"
+ Makefile = Makefile + "\t@(echo > .memdump)\n"
+ for test in tests:
+ Makefile = Makefile + "\t@(%s)\n" % (test)
+ Makefile = Makefile + '\t@(grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0)\n'
+ Makefile = Makefile + "\n\n"
+ try:
+ old = open("Makefile.am", "r").read()
+ if old != Makefile:
+ n = open("Makefile.am", "w").write(Makefile)
+ print "Updated Makefile.am"
+ except:
+ print "Failed to read or save Makefile.am"
+ #
+ # Autogenerate the .cvsignore too ...
+ #
+ ignore = """.memdump
+Makefile.in
+Makefile
+"""
+ for example in examples:
+ ignore = ignore + "%s\n" % (example)
+ try:
+ old = open(".cvsignore", "r").read()
+ if old != ignore:
+ n = open(".cvsignore", "w").write(ignore)
+ print "Updated .cvsignore"
+ except:
+ print "Failed to read or save .cvsignore"
+
+if __name__ == "__main__":
+ load_api()
+ output = open("examples.xml", "w")
+ output.write("<examples>\n")
+
+ for file in glob.glob('*.c'):
+ parse(file, output)
+ examples.append(file[:-2])
+
+ dump_symbols(output)
+ dump_sections(output)
+ output.write("</examples>\n")
+ output.close()
+ dump_Makefile()
+
diff --git a/doc/examples/io1.c b/doc/examples/io1.c
new file mode 100644
index 0000000..c8a47e3
--- /dev/null
+++ b/doc/examples/io1.c
@@ -0,0 +1,166 @@
+/**
+ * section: InputOutput
+ * synopsis: Example of custom Input/Output
+ * purpose: Demonstrate the use of xmlRegisterInputCallbacks
+ * to build a custom I/O layer, this is used in an
+ * XInclude method context to show how dynamic document can
+ * be built in a clean way.
+ * usage: io1
+ * test: io1 > io1.tmp ; diff io1.tmp io1.res ; rm -f io1.tmp
+ * author: Daniel Veillard
+ * copy: see Copyright for the status of this software.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xinclude.h>
+#include <libxml/xmlIO.h>
+
+#ifdef LIBXML_XINCLUDE_ENABLED
+static const char *result = "<list><people>a</people><people>b</people></list>";
+static const char *cur = NULL;
+static int rlen;
+
+/**
+ * sqlMatch:
+ * @URI: an URI to test
+ *
+ * Check for an sql: query
+ *
+ * Returns 1 if yes and 0 if another Input module should be used
+ */
+static int
+sqlMatch(const char * URI) {
+ if ((URI != NULL) && (!strncmp(URI, "sql:", 4)))
+ return(1);
+ return(0);
+}
+
+/**
+ * sqlOpen:
+ * @URI: an URI to test
+ *
+ * Return a pointer to the sql: query handler, in this example simply
+ * the current pointer...
+ *
+ * Returns an Input context or NULL in case or error
+ */
+static void *
+sqlOpen(const char * URI) {
+ if ((URI == NULL) || (strncmp(URI, "sql:", 4)))
+ return(NULL);
+ cur = result;
+ rlen = strlen(result);
+ return((void *) cur);
+}
+
+/**
+ * sqlClose:
+ * @context: the read context
+ *
+ * Close the sql: query handler
+ *
+ * Returns 0 or -1 in case of error
+ */
+static int
+sqlClose(void * context) {
+ if (context == NULL) return(-1);
+ cur = NULL;
+ rlen = 0;
+ return(0);
+}
+
+/**
+ * sqlRead:
+ * @context: the read context
+ * @buffer: where to store data
+ * @len: number of bytes to read
+ *
+ * Implement an sql: query read.
+ *
+ * Returns the number of bytes read or -1 in case of error
+ */
+static int
+sqlRead(void * context, char * buffer, int len) {
+ const char *ptr = (const char *) context;
+
+ if ((context == NULL) || (buffer == NULL) || (len < 0))
+ return(-1);
+
+ if (len > rlen) len = rlen;
+ memcpy(buffer, ptr, len);
+ rlen -= len;
+ return(len);
+}
+
+const char *include = "<?xml version='1.0'?>\n\
+<document xmlns:xi=\"http://www.w3.org/2003/XInclude\">\n\
+ <p>List of people:</p>\n\
+ <xi:include href=\"sql:select_name_from_people\"/>\n\
+</document>\n";
+
+int main(void) {
+ xmlDocPtr doc;
+
+ /*
+ * this initialize the library and check potential ABI mismatches
+ * between the version it was compiled for and the actual shared
+ * library used.
+ */
+ LIBXML_TEST_VERSION
+
+ /*
+ * register the new I/O handlers
+ */
+ if (xmlRegisterInputCallbacks(sqlMatch, sqlOpen, sqlRead, sqlClose) < 0) {
+ fprintf(stderr, "failed to register SQL handler\n");
+ exit(1);
+ }
+ /*
+ * parse include into a document
+ */
+ doc = xmlReadMemory(include, strlen(include), "include.xml", NULL, 0);
+ if (doc == NULL) {
+ fprintf(stderr, "failed to parse the including file\n");
+ exit(1);
+ }
+
+ /*
+ * apply the XInclude process, this should trigger the I/O just
+ * registered.
+ */
+ if (xmlXIncludeProcess(doc) <= 0) {
+ fprintf(stderr, "XInclude processing failed\n");
+ exit(1);
+ }
+
+#ifdef LIBXML_OUTPUT_ENABLED
+ /*
+ * save the output for checking to stdout
+ */
+ xmlDocDump(stdout, doc);
+#endif
+
+ /*
+ * Free the document
+ */
+ xmlFreeDoc(doc);
+
+ /*
+ * Cleanup function for the XML library.
+ */
+ xmlCleanupParser();
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
+ return(0);
+}
+#else
+int main(void) {
+ fprintf(stderr, "XInclude support not compiled in\n");
+ exit(1);
+}
+#endif
diff --git a/doc/examples/io1.res b/doc/examples/io1.res
new file mode 100644
index 0000000..4a4c036
--- /dev/null
+++ b/doc/examples/io1.res
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<document xmlns:xi="http://www.w3.org/2003/XInclude">
+ <p>List of people:</p>
+ <list><people>a</people><people>b</people></list>
+</document>
diff --git a/doc/examples/parse1.c b/doc/examples/parse1.c
new file mode 100644
index 0000000..b44b03b
--- /dev/null
+++ b/doc/examples/parse1.c
@@ -0,0 +1,56 @@
+/**
+ * section: Parsing
+ * synopsis: Parse an XML file to a tree and free it
+ * purpose: Demonstrate the use of xmlReadFile() to read an XML file
+ * into a tree and and xmlFreeDoc() to free the resulting tree
+ * usage: parse1 test1.xml
+ * test: parse1 test1.xml
+ * author: Daniel Veillard
+ * copy: see Copyright for the status of this software.
+ */
+
+#include <stdio.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+/**
+ * example1Func:
+ * @filename: a filename or an URL
+ *
+ * Parse the resource and free the resulting tree
+ */
+static void
+example1Func(const char *filename) {
+ xmlDocPtr doc; /* the resulting document tree */
+
+ doc = xmlReadFile(filename, NULL, 0);
+ if (doc == NULL) {
+ fprintf(stderr, "Failed to parse %s\n", filename);
+ return;
+ }
+ xmlFreeDoc(doc);
+}
+
+int main(int argc, char **argv) {
+ if (argc != 2)
+ return(1);
+
+ /*
+ * this initialize the library and check potential ABI mismatches
+ * between the version it was compiled for and the actual shared
+ * library used.
+ */
+ LIBXML_TEST_VERSION
+
+ example1Func(argv[1]);
+
+ /*
+ * Cleanup function for the XML library.
+ */
+ xmlCleanupParser();
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
+ return(0);
+}
diff --git a/doc/examples/parse2.c b/doc/examples/parse2.c
new file mode 100644
index 0000000..aed7676
--- /dev/null
+++ b/doc/examples/parse2.c
@@ -0,0 +1,72 @@
+/**
+ * section: Parsing
+ * synopsis: Parse and validate an XML file to a tree and free the result
+ * purpose: Create a parser context for an XML file, then parse and validate
+ * the file, creating a tree, check the validation result
+ * and xmlFreeDoc() to free the resulting tree.
+ * usage: parse2 test2.xml
+ * test: parse2 test2.xml
+ * author: Daniel Veillard
+ * copy: see Copyright for the status of this software.
+ */
+
+#include <stdio.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+/**
+ * exampleFunc:
+ * @filename: a filename or an URL
+ *
+ * Parse and validate the resource and free the resulting tree
+ */
+static void
+exampleFunc(const char *filename) {
+ xmlParserCtxtPtr ctxt; /* the parser context */
+ xmlDocPtr doc; /* the resulting document tree */
+
+ /* create a parser context */
+ ctxt = xmlNewParserCtxt();
+ if (ctxt == NULL) {
+ fprintf(stderr, "Failed to allocate parser context\n");
+ return;
+ }
+ /* parse the file, activating the DTD validation option */
+ doc = xmlCtxtReadFile(ctxt, filename, NULL, XML_PARSE_DTDVALID);
+ /* check if parsing suceeded */
+ if (doc == NULL) {
+ fprintf(stderr, "Failed to parse %s\n", filename);
+ } else {
+ /* check if validation suceeded */
+ if (ctxt->valid == 0)
+ fprintf(stderr, "Failed to validate %s\n", filename);
+ /* free up the resulting document */
+ xmlFreeDoc(doc);
+ }
+ /* free up the parser context */
+ xmlFreeParserCtxt(ctxt);
+}
+
+int main(int argc, char **argv) {
+ if (argc != 2)
+ return(1);
+
+ /*
+ * this initialize the library and check potential ABI mismatches
+ * between the version it was compiled for and the actual shared
+ * library used.
+ */
+ LIBXML_TEST_VERSION
+
+ exampleFunc(argv[1]);
+
+ /*
+ * Cleanup function for the XML library.
+ */
+ xmlCleanupParser();
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
+ return(0);
+}
diff --git a/doc/examples/reader1.c b/doc/examples/reader1.c
new file mode 100644
index 0000000..90db2a1
--- /dev/null
+++ b/doc/examples/reader1.c
@@ -0,0 +1,107 @@
+/**
+ * section: xmlReader
+ * synopsis: Parse an XML file with an xmlReader
+ * purpose: Demonstrate the use of xmlReaderForFile() to parse an XML file
+ * and dump the informations about the nodes found in the process.
+ * (Note that the XMLReader functions require libxml2 version later
+ * than 2.6.)
+ * usage: reader1 <filename>
+ * test: reader1 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp
+ * author: Daniel Veillard
+ * copy: see Copyright for the status of this software.
+ */
+
+#include <stdio.h>
+#include <libxml/xmlreader.h>
+
+#ifdef LIBXML_READER_ENABLED
+
+/**
+ * processNode:
+ * @reader: the xmlReader
+ *
+ * Dump information about the current node
+ */
+static void
+processNode(xmlTextReaderPtr reader) {
+ const xmlChar *name, *value;
+
+ name = xmlTextReaderConstName(reader);
+ if (name == NULL)
+ name = BAD_CAST "--";
+
+ value = xmlTextReaderConstValue(reader);
+
+ printf("%d %d %s %d %d",
+ xmlTextReaderDepth(reader),
+ xmlTextReaderNodeType(reader),
+ name,
+ xmlTextReaderIsEmptyElement(reader),
+ xmlTextReaderHasValue(reader));
+ if (value == NULL)
+ printf("\n");
+ else {
+ if (xmlStrlen(value) > 40)
+ printf(" %.40s...\n", value);
+ else
+ printf(" %s\n", value);
+ }
+}
+
+/**
+ * streamFile:
+ * @filename: the file name to parse
+ *
+ * Parse and print information about an XML file.
+ */
+static void
+streamFile(const char *filename) {
+ xmlTextReaderPtr reader;
+ int ret;
+
+ reader = xmlReaderForFile(filename, NULL, 0);
+ if (reader != NULL) {
+ ret = xmlTextReaderRead(reader);
+ while (ret == 1) {
+ processNode(reader);
+ ret = xmlTextReaderRead(reader);
+ }
+ xmlFreeTextReader(reader);
+ if (ret != 0) {
+ fprintf(stderr, "%s : failed to parse\n", filename);
+ }
+ } else {
+ fprintf(stderr, "Unable to open %s\n", filename);
+ }
+}
+
+int main(int argc, char **argv) {
+ if (argc != 2)
+ return(1);
+
+ /*
+ * this initialize the library and check potential ABI mismatches
+ * between the version it was compiled for and the actual shared
+ * library used.
+ */
+ LIBXML_TEST_VERSION
+
+ streamFile(argv[1]);
+
+ /*
+ * Cleanup function for the XML library.
+ */
+ xmlCleanupParser();
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
+ return(0);
+}
+
+#else
+int main(void) {
+ fprintf(stderr, "XInclude support not compiled in\n");
+ exit(1);
+}
+#endif
diff --git a/doc/examples/reader1.res b/doc/examples/reader1.res
new file mode 100644
index 0000000..eb48d85
--- /dev/null
+++ b/doc/examples/reader1.res
@@ -0,0 +1,14 @@
+0 10 doc 0 0
+0 1 doc 0 0
+1 14 #text 0 1
+
+1 1 src 1 0
+1 14 #text 0 1
+
+1 1 dest 1 0
+1 14 #text 0 1
+
+1 1 src 1 0
+1 14 #text 0 1
+
+0 15 doc 0 0
diff --git a/doc/examples/reader2.c b/doc/examples/reader2.c
new file mode 100644
index 0000000..c32ada5
--- /dev/null
+++ b/doc/examples/reader2.c
@@ -0,0 +1,122 @@
+/**
+ * section: xmlReader
+ * synopsis: Parse and validate an XML file with an xmlReader
+ * purpose: Demonstrate the use of xmlReaderForFile() to parse an XML file
+ * validating the content in the process and activating options
+ * like entities substitution, and DTD attributes defaulting.
+ * (Note that the XMLReader functions require libxml2 version later
+ * than 2.6.)
+ * usage: reader2 <valid_xml_filename>
+ * test: reader2 test2.xml > reader1.tmp ; diff reader1.tmp reader1.res ; rm reader1.tmp
+ * author: Daniel Veillard
+ * copy: see Copyright for the status of this software.
+ */
+
+#include <stdio.h>
+#include <libxml/xmlreader.h>
+
+#ifdef LIBXML_READER_ENABLED
+
+/**
+ * processNode:
+ * @reader: the xmlReader
+ *
+ * Dump information about the current node
+ */
+static void
+processNode(xmlTextReaderPtr reader) {
+ const xmlChar *name, *value;
+
+ name = xmlTextReaderConstName(reader);
+ if (name == NULL)
+ name = BAD_CAST "--";
+
+ value = xmlTextReaderConstValue(reader);
+
+ printf("%d %d %s %d %d",
+ xmlTextReaderDepth(reader),
+ xmlTextReaderNodeType(reader),
+ name,
+ xmlTextReaderIsEmptyElement(reader),
+ xmlTextReaderHasValue(reader));
+ if (value == NULL)
+ printf("\n");
+ else {
+ if (xmlStrlen(value) > 40)
+ printf(" %.40s...\n", value);
+ else
+ printf(" %s\n", value);
+ }
+}
+
+/**
+ * streamFile:
+ * @filename: the file name to parse
+ *
+ * Parse, validate and print information about an XML file.
+ */
+static void
+streamFile(const char *filename) {
+ xmlTextReaderPtr reader;
+ int ret;
+
+
+ /*
+ * Pass some special parsing options to activate DTD attribute defaulting,
+ * entities substitution and DTD validation
+ */
+ reader = xmlReaderForFile(filename, NULL,
+ XML_PARSE_DTDATTR | /* default DTD attributes */
+ XML_PARSE_NOENT | /* substitute entities */
+ XML_PARSE_DTDVALID); /* validate with the DTD */
+ if (reader != NULL) {
+ ret = xmlTextReaderRead(reader);
+ while (ret == 1) {
+ processNode(reader);
+ ret = xmlTextReaderRead(reader);
+ }
+ /*
+ * Once the document has been fully parsed check the validation results
+ */
+ if (xmlTextReaderIsValid(reader) != 1) {
+ fprintf(stderr, "Document %s does not validate\n", filename);
+ }
+ xmlFreeTextReader(reader);
+ if (ret != 0) {
+ fprintf(stderr, "%s : failed to parse\n", filename);
+ }
+ } else {
+ fprintf(stderr, "Unable to open %s\n", filename);
+ }
+}
+
+int main(int argc, char **argv) {
+ if (argc != 2)
+ return(1);
+
+ /*
+ * this initialize the library and check potential ABI mismatches
+ * between the version it was compiled for and the actual shared
+ * library used.
+ */
+ LIBXML_TEST_VERSION
+
+ streamFile(argv[1]);
+
+ /*
+ * Cleanup function for the XML library.
+ */
+ xmlCleanupParser();
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
+ return(0);
+}
+
+#else
+int main(void) {
+ fprintf(stderr, "XInclude support not compiled in\n");
+ exit(1);
+}
+#endif
diff --git a/doc/examples/reader3.c b/doc/examples/reader3.c
new file mode 100644
index 0000000..2da7532
--- /dev/null
+++ b/doc/examples/reader3.c
@@ -0,0 +1,119 @@
+/**
+ * section: xmlReader
+ * synopsis: Show how to extract subdocuments with xmlReader
+ * purpose: Demonstrate the use of xmlTextReaderPreservePattern()
+ * to parse an XML file with the xmlReader while collecting
+ * only some subparts of the document.
+ * (Note that the XMLReader functions require libxml2 version later
+ * than 2.6.)
+ * usage: reader3
+ * test: reader3 > reader3.tmp ; diff reader3.tmp reader3.res ; rm reader3.tmp
+ * author: Daniel Veillard
+ * copy: see Copyright for the status of this software.
+ */
+
+#include <stdio.h>
+#include <libxml/xmlreader.h>
+
+#ifdef LIBXML_READER_ENABLED
+
+/**
+ * streamFile:
+ * @filename: the file name to parse
+ *
+ * Parse and print information about an XML file.
+ *
+ * Returns the resulting doc with just the elements preserved.
+ */
+static xmlDocPtr
+extractFile(const char *filename, const xmlChar *pattern) {
+ xmlDocPtr doc;
+ xmlTextReaderPtr reader;
+ int ret;
+
+ /*
+ * build an xmlReader for that file
+ */
+ reader = xmlReaderForFile(filename, NULL, 0);
+ if (reader != NULL) {
+ /*
+ * add the pattern to preserve
+ */
+ if (xmlTextReaderPreservePattern(reader, pattern, NULL) < 0) {
+ fprintf(stderr, "%s : failed add preserve pattern %s\n",
+ filename, (const char *) pattern);
+ }
+ /*
+ * Parse and traverse the tree, collecting the nodes in the process
+ */
+ ret = xmlTextReaderRead(reader);
+ while (ret == 1) {
+ ret = xmlTextReaderRead(reader);
+ }
+ if (ret != 0) {
+ fprintf(stderr, "%s : failed to parse\n", filename);
+ xmlFreeTextReader(reader);
+ return(NULL);
+ }
+ /*
+ * get the resulting nodes
+ */
+ doc = xmlTextReaderCurrentDoc(reader);
+ /*
+ * Free up the reader
+ */
+ xmlFreeTextReader(reader);
+ } else {
+ fprintf(stderr, "Unable to open %s\n", filename);
+ return(NULL);
+ }
+ return(doc);
+}
+
+int main(int argc, char **argv) {
+ const char *filename = "test3.xml";
+ const char *pattern = "preserved";
+ xmlDocPtr doc;
+
+ if (argc == 3) {
+ filename = argv[1];
+ pattern = argv[2];
+ }
+
+ /*
+ * this initialize the library and check potential ABI mismatches
+ * between the version it was compiled for and the actual shared
+ * library used.
+ */
+ LIBXML_TEST_VERSION
+
+ doc = extractFile(filename, (const xmlChar *) pattern);
+ if (doc != NULL) {
+ /*
+ * ouptut the result.
+ */
+ xmlDocDump(stdout, doc);
+ /*
+ * don't forget to free up the doc
+ */
+ xmlFreeDoc(doc);
+ }
+
+
+ /*
+ * Cleanup function for the XML library.
+ */
+ xmlCleanupParser();
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
+ return(0);
+}
+
+#else
+int main(void) {
+ fprintf(stderr, "XInclude support not compiled in\n");
+ exit(1);
+}
+#endif
diff --git a/doc/examples/reader3.res b/doc/examples/reader3.res
new file mode 100644
index 0000000..20e2e82
--- /dev/null
+++ b/doc/examples/reader3.res
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+<doc><parent><preserved/><preserved>
+ content1
+ <child1/>
+ <child2>content2</child2>
+ <preserved>too</preserved>
+ <child2>content3</child2>
+ <preserved/>
+ <child2>content4</child2>
+ <preserved/>
+ <child2>content5</child2>
+ content6
+ </preserved><preserved/><preserved/></parent></doc>
diff --git a/doc/examples/test1.xml b/doc/examples/test1.xml
new file mode 100644
index 0000000..69d62f2
--- /dev/null
+++ b/doc/examples/test1.xml
@@ -0,0 +1 @@
+<doc/>
diff --git a/doc/examples/test2.xml b/doc/examples/test2.xml
new file mode 100644
index 0000000..7390f5e
--- /dev/null
+++ b/doc/examples/test2.xml
@@ -0,0 +1,13 @@
+<!DOCTYPE doc [
+<!ELEMENT doc (src | dest)*>
+<!ELEMENT src EMPTY>
+<!ELEMENT dest EMPTY>
+<!ATTLIST src ref IDREF #IMPLIED>
+<!ATTLIST dest id ID #IMPLIED>
+]>
+<doc>
+ <src ref="foo"/>
+ <dest id="foo"/>
+ <src ref="foo"/>
+</doc>
+
diff --git a/doc/examples/test3.xml b/doc/examples/test3.xml
new file mode 100644
index 0000000..4d0828f
--- /dev/null
+++ b/doc/examples/test3.xml
@@ -0,0 +1,39 @@
+<doc>
+ <parent>
+ <discarded>
+ <discarded/>
+ </discarded>
+ <preserved/>
+ This text node must be discarded
+ <discarded>
+ <discarded/>
+ </discarded>
+ <preserved>
+ content1
+ <child1></child1>
+ <child2>content2</child2>
+ <preserved>too</preserved>
+ <child2>content3</child2>
+ <preserved></preserved>
+ <child2>content4</child2>
+ <preserved/>
+ <child2>content5</child2>
+ content6
+ </preserved>
+ This text node must be discarded
+ <discarded>
+ <discarded/>
+ </discarded>
+ This text node must be discarded
+ <preserved></preserved>
+ This text node must be discarded
+ <preserved/>
+ This text node must be discarded
+ <discarded>
+ <discarded/>
+ </discarded>
+ This text node must be discarded
+ </parent>
+</doc>
+
+
diff --git a/doc/examples/testWriter.c b/doc/examples/testWriter.c
new file mode 100644
index 0000000..02f9eb7
--- /dev/null
+++ b/doc/examples/testWriter.c
@@ -0,0 +1,1198 @@
+/**
+ * section: xmlWriter
+ * synopsis: use various APIs for the xmlWriter
+ * purpose: tests a number of APIs for the xmlWriter, especially
+ * the various methods to write to a filename, to a memory
+ * buffer, to a new document, or to a subtree. It shows how to
+ * do encoding string conversions too. The resulting
+ * documents are then serialized.
+ * usage: testWriter
+ * test: testWriter ; for i in 1 2 3 4 ; do diff writer.xml writer$$i.res ; done ; rm writer*.res
+ * author: Alfred Mickautsch
+ * copy: see Copyright for the status of this software.
+ */
+#include <stdio.h>
+#include <string.h>
+#include <libxml/encoding.h>
+#include <libxml/xmlwriter.h>
+
+#if defined(LIBXML_WRITER_ENABLED) && defined(LIBXML_OUTPUT_ENABLED)
+
+#define MY_ENCODING "ISO-8859-1"
+
+void testXmlwriterFilename(const char *uri);
+void testXmlwriterMemory(const char *file);
+void testXmlwriterDoc(const char *file);
+void testXmlwriterTree(const char *file);
+xmlChar *ConvertInput(const char *in, const char *encoding);
+
+int
+main(void)
+{
+ /*
+ * this initialize the library and check potential ABI mismatches
+ * between the version it was compiled for and the actual shared
+ * library used.
+ */
+ LIBXML_TEST_VERSION
+
+ /* first, the file version */
+ testXmlwriterFilename("writer1.res");
+
+ /* next, the memory version */
+ testXmlwriterMemory("writer2.res");
+
+ /* next, the DOM version */
+ testXmlwriterDoc("writer3.res");
+
+ /* next, the tree version */
+ testXmlwriterTree("writer4.res");
+
+ /*
+ * Cleanup function for the XML library.
+ */
+ xmlCleanupParser();
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
+ return 0;
+}
+
+/**
+ * testXmlwriterFilename:
+ * @uri: the output URI
+ *
+ * test the xmlWriter interface when writing to a new file
+ */
+void
+testXmlwriterFilename(const char *uri)
+{
+ int rc;
+ xmlTextWriterPtr writer;
+ xmlChar *tmp;
+
+ /* Create a new XmlWriter for uri, with no compression. */
+ writer = xmlNewTextWriterFilename(uri, 0);
+ if (writer == NULL) {
+ printf("testXmlwriterFilename: Error creating the xml writer\n");
+ return;
+ }
+
+ /* Start the document with the xml default for the version,
+ * encoding ISO 8858-1 and the default for the standalone
+ * declaration. */
+ rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterStartDocument\n");
+ return;
+ }
+
+ /* Start an element named "EXAMPLE". Since thist is the first
+ * element, this will be the root element of the document. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "EXAMPLE");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write a comment as child of EXAMPLE.
+ * Please observe, that the input to the xmlTextWriter functions
+ * HAS to be in UTF-8, even if the output XML is encoded
+ * in iso-8859-1 */
+ tmp = ConvertInput("This is a comment with special chars: <äöü>",
+ MY_ENCODING);
+ rc = xmlTextWriterWriteComment(writer, tmp);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterWriteComment\n");
+ return;
+ }
+ if (tmp != NULL) xmlFree(tmp);
+
+ /* Start an element named "ORDER" as child of EXAMPLE. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Add an attribute with name "version" and value "1.0" to ORDER. */
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "version",
+ BAD_CAST "1.0");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute\n");
+ return;
+ }
+
+ /* Add an attribute with name "xml:lang" and value "de" to ORDER. */
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
+ BAD_CAST "de");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterWriteAttribute\n");
+ return;
+ }
+
+ /* Write a comment as child of ORDER */
+ tmp = ConvertInput("<äöü>", MY_ENCODING);
+ rc = xmlTextWriterWriteFormatComment(writer,
+ "This is another comment with special chars: %s",
+ tmp);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterWriteFormatComment\n");
+ return;
+ }
+ if (tmp != NULL) xmlFree(tmp);
+
+ /* Start an element named "HEADER" as child of ORDER. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write an element named "X_ORDER_ID" as child of HEADER. */
+ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "X_ORDER_ID",
+ "%010d", 53535L);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
+ return;
+ }
+
+ /* Write an element named "CUSTOMER_ID" as child of HEADER. */
+ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CUSTOMER_ID",
+ "%d", 1010);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
+ return;
+ }
+
+ /* Write an element named "NAME_1" as child of HEADER. */
+ tmp = ConvertInput("Müller", MY_ENCODING);
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+ if (tmp != NULL) xmlFree(tmp);
+
+ /* Write an element named "NAME_2" as child of HEADER. */
+ tmp = ConvertInput("Jörg", MY_ENCODING);
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+ if (tmp != NULL) xmlFree(tmp);
+
+ /* Close the element named HEADER. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Start an element named "ENTRIES" as child of ORDER. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRIES");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Start an element named "ENTRY" as child of ENTRIES. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write an element named "ARTICLE" as child of ENTRY. */
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "ARTICLE",
+ BAD_CAST "<Test>");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+
+ /* Write an element named "ENTRY_NO" as child of ENTRY. */
+ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENTRY_NO", "%d",
+ 10);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
+ return;
+ }
+
+ /* Close the element named ENTRY. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Start an element named "ENTRY" as child of ENTRIES. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write an element named "ARTICLE" as child of ENTRY. */
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "ARTICLE",
+ BAD_CAST "<Test 2>");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+
+ /* Write an element named "ENTRY_NO" as child of ENTRY. */
+ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENTRY_NO", "%d",
+ 20);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterWriteFormatElement\n");
+ return;
+ }
+
+ /* Close the element named ENTRY. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Close the element named ENTRIES. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Start an element named "FOOTER" as child of ORDER. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "FOOTER");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write an element named "TEXT" as child of FOOTER. */
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "TEXT",
+ BAD_CAST "This is a text.");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+
+ /* Close the element named FOOTER. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Here we could close the elements ORDER and EXAMPLE using the
+ * function xmlTextWriterEndElement, but since we do not want to
+ * write any other elements, we simply call xmlTextWriterEndDocument,
+ * which will do all the work. */
+ rc = xmlTextWriterEndDocument(writer);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterFilename: Error at xmlTextWriterEndDocument\n");
+ return;
+ }
+
+ xmlFreeTextWriter(writer);
+}
+
+/**
+ * testXmlwriterMemory:
+ * @file: the output file
+ *
+ * test the xmlWriter interface when writing to memory
+ */
+void
+testXmlwriterMemory(const char *file)
+{
+ int rc;
+ xmlTextWriterPtr writer;
+ xmlBufferPtr buf;
+ xmlChar *tmp;
+ FILE *fp;
+
+ /* Create a new XML buffer, to which the XML document will be
+ * written */
+ buf = xmlBufferCreate();
+ if (buf == NULL) {
+ printf("testXmlwriterMemory: Error creating the xml buffer\n");
+ return;
+ }
+
+ /* Create a new XmlWriter for memory, with no compression.
+ * Remark: there is no compression for this kind of xmlTextWriter */
+ writer = xmlNewTextWriterMemory(buf, 0);
+ if (writer == NULL) {
+ printf("testXmlwriterMemory: Error creating the xml writer\n");
+ return;
+ }
+
+ /* Start the document with the xml default for the version,
+ * encoding ISO 8858-1 and the default for the standalone
+ * declaration. */
+ rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterStartDocument\n");
+ return;
+ }
+
+ /* Start an element named "EXAMPLE". Since thist is the first
+ * element, this will be the root element of the document. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "EXAMPLE");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write a comment as child of EXAMPLE.
+ * Please observe, that the input to the xmlTextWriter functions
+ * HAS to be in UTF-8, even if the output XML is encoded
+ * in iso-8859-1 */
+ tmp = ConvertInput("This is a comment with special chars: <äöü>",
+ MY_ENCODING);
+ rc = xmlTextWriterWriteComment(writer, tmp);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterWriteComment\n");
+ return;
+ }
+ if (tmp != NULL) xmlFree(tmp);
+
+ /* Start an element named "ORDER" as child of EXAMPLE. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Add an attribute with name "version" and value "1.0" to ORDER. */
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "version",
+ BAD_CAST "1.0");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterWriteAttribute\n");
+ return;
+ }
+
+ /* Add an attribute with name "xml:lang" and value "de" to ORDER. */
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
+ BAD_CAST "de");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterWriteAttribute\n");
+ return;
+ }
+
+ /* Write a comment as child of ORDER */
+ tmp = ConvertInput("<äöü>", MY_ENCODING);
+ rc = xmlTextWriterWriteFormatComment(writer,
+ "This is another comment with special chars: %s",
+ tmp);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterWriteFormatComment\n");
+ return;
+ }
+ if (tmp != NULL) xmlFree(tmp);
+
+ /* Start an element named "HEADER" as child of ORDER. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write an element named "X_ORDER_ID" as child of HEADER. */
+ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "X_ORDER_ID",
+ "%010d", 53535L);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterWriteFormatElement\n");
+ return;
+ }
+
+ /* Write an element named "CUSTOMER_ID" as child of HEADER. */
+ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CUSTOMER_ID",
+ "%d", 1010);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterWriteFormatElement\n");
+ return;
+ }
+
+ /* Write an element named "NAME_1" as child of HEADER. */
+ tmp = ConvertInput("Müller", MY_ENCODING);
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+ if (tmp != NULL) xmlFree(tmp);
+
+ /* Write an element named "NAME_2" as child of HEADER. */
+ tmp = ConvertInput("Jörg", MY_ENCODING);
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp);
+
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+ if (tmp != NULL) xmlFree(tmp);
+
+ /* Close the element named HEADER. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf("testXmlwriterMemory: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Start an element named "ENTRIES" as child of ORDER. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRIES");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Start an element named "ENTRY" as child of ENTRIES. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write an element named "ARTICLE" as child of ENTRY. */
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "ARTICLE",
+ BAD_CAST "<Test>");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+
+ /* Write an element named "ENTRY_NO" as child of ENTRY. */
+ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENTRY_NO", "%d",
+ 10);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterWriteFormatElement\n");
+ return;
+ }
+
+ /* Close the element named ENTRY. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf("testXmlwriterMemory: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Start an element named "ENTRY" as child of ENTRIES. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write an element named "ARTICLE" as child of ENTRY. */
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "ARTICLE",
+ BAD_CAST "<Test 2>");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+
+ /* Write an element named "ENTRY_NO" as child of ENTRY. */
+ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENTRY_NO", "%d",
+ 20);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterWriteFormatElement\n");
+ return;
+ }
+
+ /* Close the element named ENTRY. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf("testXmlwriterMemory: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Close the element named ENTRIES. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf("testXmlwriterMemory: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Start an element named "FOOTER" as child of ORDER. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "FOOTER");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write an element named "TEXT" as child of FOOTER. */
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "TEXT",
+ BAD_CAST "This is a text.");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterMemory: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+
+ /* Close the element named FOOTER. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf("testXmlwriterMemory: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Here we could close the elements ORDER and EXAMPLE using the
+ * function xmlTextWriterEndElement, but since we do not want to
+ * write any other elements, we simply call xmlTextWriterEndDocument,
+ * which will do all the work. */
+ rc = xmlTextWriterEndDocument(writer);
+ if (rc < 0) {
+ printf("testXmlwriterMemory: Error at xmlTextWriterEndDocument\n");
+ return;
+ }
+
+ xmlFreeTextWriter(writer);
+
+ fp = fopen(file, "w");
+ if (fp == NULL) {
+ printf("testXmlwriterMemory: Error at fopen\n");
+ return;
+ }
+
+ fprintf(fp, "%s", (const char *) buf->content);
+
+ fclose(fp);
+
+ xmlBufferFree(buf);
+}
+
+/**
+ * testXmlwriterDoc:
+ * @file: the output file
+ *
+ * test the xmlWriter interface when creating a new document
+ */
+void
+testXmlwriterDoc(const char *file)
+{
+ int rc;
+ xmlTextWriterPtr writer;
+ xmlChar *tmp;
+ xmlDocPtr doc;
+
+
+ /* Create a new XmlWriter for DOM, with no compression. */
+ writer = xmlNewTextWriterDoc(&doc, 0);
+ if (writer == NULL) {
+ printf("testXmlwriterDoc: Error creating the xml writer\n");
+ return;
+ }
+
+ /* Start the document with the xml default for the version,
+ * encoding ISO 8858-1 and the default for the standalone
+ * declaration. */
+ rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL);
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterStartDocument\n");
+ return;
+ }
+
+ /* Start an element named "EXAMPLE". Since thist is the first
+ * element, this will be the root element of the document. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "EXAMPLE");
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write a comment as child of EXAMPLE.
+ * Please observe, that the input to the xmlTextWriter functions
+ * HAS to be in UTF-8, even if the output XML is encoded
+ * in iso-8859-1 */
+ tmp = ConvertInput("This is a comment with special chars: <äöü>",
+ MY_ENCODING);
+ rc = xmlTextWriterWriteComment(writer, tmp);
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterWriteComment\n");
+ return;
+ }
+ if (tmp != NULL) xmlFree(tmp);
+
+ /* Start an element named "ORDER" as child of EXAMPLE. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER");
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Add an attribute with name "version" and value "1.0" to ORDER. */
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "version",
+ BAD_CAST "1.0");
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterWriteAttribute\n");
+ return;
+ }
+
+ /* Add an attribute with name "xml:lang" and value "de" to ORDER. */
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
+ BAD_CAST "de");
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterWriteAttribute\n");
+ return;
+ }
+
+ /* Write a comment as child of ORDER */
+ tmp = ConvertInput("<äöü>", MY_ENCODING);
+ rc = xmlTextWriterWriteFormatComment(writer,
+ "This is another comment with special chars: %s",
+ tmp);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterDoc: Error at xmlTextWriterWriteFormatComment\n");
+ return;
+ }
+ if (tmp != NULL) xmlFree(tmp);
+
+ /* Start an element named "HEADER" as child of ORDER. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write an element named "X_ORDER_ID" as child of HEADER. */
+ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "X_ORDER_ID",
+ "%010d", 53535L);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterDoc: Error at xmlTextWriterWriteFormatElement\n");
+ return;
+ }
+
+ /* Write an element named "CUSTOMER_ID" as child of HEADER. */
+ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CUSTOMER_ID",
+ "%d", 1010);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterDoc: Error at xmlTextWriterWriteFormatElement\n");
+ return;
+ }
+
+ /* Write an element named "NAME_1" as child of HEADER. */
+ tmp = ConvertInput("Müller", MY_ENCODING);
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp);
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+ if (tmp != NULL) xmlFree(tmp);
+
+ /* Write an element named "NAME_2" as child of HEADER. */
+ tmp = ConvertInput("Jörg", MY_ENCODING);
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp);
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+ if (tmp != NULL) xmlFree(tmp);
+
+ /* Close the element named HEADER. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Start an element named "ENTRIES" as child of ORDER. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRIES");
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Start an element named "ENTRY" as child of ENTRIES. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY");
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write an element named "ARTICLE" as child of ENTRY. */
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "ARTICLE",
+ BAD_CAST "<Test>");
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+
+ /* Write an element named "ENTRY_NO" as child of ENTRY. */
+ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENTRY_NO", "%d",
+ 10);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterDoc: Error at xmlTextWriterWriteFormatElement\n");
+ return;
+ }
+
+ /* Close the element named ENTRY. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Start an element named "ENTRY" as child of ENTRIES. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY");
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write an element named "ARTICLE" as child of ENTRY. */
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "ARTICLE",
+ BAD_CAST "<Test 2>");
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+
+ /* Write an element named "ENTRY_NO" as child of ENTRY. */
+ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENTRY_NO", "%d",
+ 20);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterDoc: Error at xmlTextWriterWriteFormatElement\n");
+ return;
+ }
+
+ /* Close the element named ENTRY. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Close the element named ENTRIES. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Start an element named "FOOTER" as child of ORDER. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "FOOTER");
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write an element named "TEXT" as child of FOOTER. */
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "TEXT",
+ BAD_CAST "This is a text.");
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+
+ /* Close the element named FOOTER. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Here we could close the elements ORDER and EXAMPLE using the
+ * function xmlTextWriterEndElement, but since we do not want to
+ * write any other elements, we simply call xmlTextWriterEndDocument,
+ * which will do all the work. */
+ rc = xmlTextWriterEndDocument(writer);
+ if (rc < 0) {
+ printf("testXmlwriterDoc: Error at xmlTextWriterEndDocument\n");
+ return;
+ }
+
+ xmlFreeTextWriter(writer);
+
+ xmlSaveFileEnc(file, doc, MY_ENCODING);
+
+ xmlFreeDoc(doc);
+}
+
+/**
+ * testXmlwriterTree:
+ * @file: the output file
+ *
+ * test the xmlWriter interface when writing to a subtree
+ */
+void
+testXmlwriterTree(const char *file)
+{
+ int rc;
+ xmlTextWriterPtr writer;
+ xmlDocPtr doc;
+ xmlNodePtr node;
+ xmlChar *tmp;
+
+ /* Create a new XML DOM tree, to which the XML document will be
+ * written */
+ doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION);
+ if (doc == NULL) {
+ printf
+ ("testXmlwriterTree: Error creating the xml document tree\n");
+ return;
+ }
+
+ /* Create a new XML node, to which the XML document will be
+ * appended */
+ node = xmlNewDocNode(doc, NULL, BAD_CAST "EXAMPLE", NULL);
+ if (node == NULL) {
+ printf("testXmlwriterTree: Error creating the xml node\n");
+ return;
+ }
+
+ /* Make ELEMENT the root node of the tree */
+ xmlDocSetRootElement(doc, node);
+
+ /* Create a new XmlWriter for DOM tree, with no compression. */
+ writer = xmlNewTextWriterTree(doc, node, 0);
+ if (writer == NULL) {
+ printf("testXmlwriterTree: Error creating the xml writer\n");
+ return;
+ }
+
+ /* Start the document with the xml default for the version,
+ * encoding ISO 8858-1 and the default for the standalone
+ * declaration. */
+ rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL);
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterStartDocument\n");
+ return;
+ }
+
+ /* Write a comment as child of EXAMPLE.
+ * Please observe, that the input to the xmlTextWriter functions
+ * HAS to be in UTF-8, even if the output XML is encoded
+ * in iso-8859-1 */
+ tmp = ConvertInput("This is a comment with special chars: <äöü>",
+ MY_ENCODING);
+ rc = xmlTextWriterWriteComment(writer, tmp);
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterWriteComment\n");
+ return;
+ }
+ if (tmp != NULL) xmlFree(tmp);
+
+ /* Start an element named "ORDER" as child of EXAMPLE. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "ORDER");
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Add an attribute with name "version" and value "1.0" to ORDER. */
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "version",
+ BAD_CAST "1.0");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterTree: Error at xmlTextWriterWriteAttribute\n");
+ return;
+ }
+
+ /* Add an attribute with name "xml:lang" and value "de" to ORDER. */
+ rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xml:lang",
+ BAD_CAST "de");
+ if (rc < 0) {
+ printf
+ ("testXmlwriterTree: Error at xmlTextWriterWriteAttribute\n");
+ return;
+ }
+
+ /* Write a comment as child of ORDER */
+ tmp = ConvertInput("<äöü>", MY_ENCODING);
+ rc = xmlTextWriterWriteFormatComment(writer,
+ "This is another comment with special chars: %s",
+ tmp);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterTree: Error at xmlTextWriterWriteFormatComment\n");
+ return;
+ }
+ if (tmp != NULL) xmlFree(tmp);
+
+ /* Start an element named "HEADER" as child of ORDER. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "HEADER");
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write an element named "X_ORDER_ID" as child of HEADER. */
+ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "X_ORDER_ID",
+ "%010d", 53535L);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterTree: Error at xmlTextWriterWriteFormatElement\n");
+ return;
+ }
+
+ /* Write an element named "CUSTOMER_ID" as child of HEADER. */
+ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "CUSTOMER_ID",
+ "%d", 1010);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterTree: Error at xmlTextWriterWriteFormatElement\n");
+ return;
+ }
+
+ /* Write an element named "NAME_1" as child of HEADER. */
+ tmp = ConvertInput("Müller", MY_ENCODING);
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_1", tmp);
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+ if (tmp != NULL) xmlFree(tmp);
+
+ /* Write an element named "NAME_2" as child of HEADER. */
+ tmp = ConvertInput("Jörg", MY_ENCODING);
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "NAME_2", tmp);
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+ if (tmp != NULL) xmlFree(tmp);
+
+ /* Close the element named HEADER. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Start an element named "ENTRIES" as child of ORDER. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRIES");
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Start an element named "ENTRY" as child of ENTRIES. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY");
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write an element named "ARTICLE" as child of ENTRY. */
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "ARTICLE",
+ BAD_CAST "<Test>");
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+
+ /* Write an element named "ENTRY_NO" as child of ENTRY. */
+ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENTRY_NO", "%d",
+ 10);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterTree: Error at xmlTextWriterWriteFormatElement\n");
+ return;
+ }
+
+ /* Close the element named ENTRY. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Start an element named "ENTRY" as child of ENTRIES. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "ENTRY");
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write an element named "ARTICLE" as child of ENTRY. */
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "ARTICLE",
+ BAD_CAST "<Test 2>");
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+
+ /* Write an element named "ENTRY_NO" as child of ENTRY. */
+ rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "ENTRY_NO", "%d",
+ 20);
+ if (rc < 0) {
+ printf
+ ("testXmlwriterTree: Error at xmlTextWriterWriteFormatElement\n");
+ return;
+ }
+
+ /* Close the element named ENTRY. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Close the element named ENTRIES. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Start an element named "FOOTER" as child of ORDER. */
+ rc = xmlTextWriterStartElement(writer, BAD_CAST "FOOTER");
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterStartElement\n");
+ return;
+ }
+
+ /* Write an element named "TEXT" as child of FOOTER. */
+ rc = xmlTextWriterWriteElement(writer, BAD_CAST "TEXT",
+ BAD_CAST "This is a text.");
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterWriteElement\n");
+ return;
+ }
+
+ /* Close the element named FOOTER. */
+ rc = xmlTextWriterEndElement(writer);
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterEndElement\n");
+ return;
+ }
+
+ /* Here we could close the elements ORDER and EXAMPLE using the
+ * function xmlTextWriterEndElement, but since we do not want to
+ * write any other elements, we simply call xmlTextWriterEndDocument,
+ * which will do all the work. */
+ rc = xmlTextWriterEndDocument(writer);
+ if (rc < 0) {
+ printf("testXmlwriterTree: Error at xmlTextWriterEndDocument\n");
+ return;
+ }
+
+ xmlFreeTextWriter(writer);
+
+ xmlSaveFileEnc(file, doc, MY_ENCODING);
+
+ xmlFreeDoc(doc);
+}
+
+/**
+ * ConvertInput:
+ * @in: string in a given encoding
+ * @encoding: the encoding used
+ *
+ * Converts @in into UTF-8 for processing with libxml2 APIs
+ *
+ * Returns the converted UTF-8 string, or NULL in case of error.
+ */
+xmlChar *
+ConvertInput(const char *in, const char *encoding)
+{
+ xmlChar *out;
+ int ret;
+ int size;
+ int out_size;
+ int temp;
+ xmlCharEncodingHandlerPtr handler;
+
+ if (in == 0)
+ return 0;
+
+ handler = xmlFindCharEncodingHandler(encoding);
+
+ if (!handler) {
+ printf("ConvertInput: no encoding handler found for '%s'\n",
+ encoding ? encoding : "");
+ return 0;
+ }
+
+ size = (int) strlen(in) + 1;
+ out_size = size * 2 - 1;
+ out = (unsigned char *) xmlMalloc((size_t) out_size);
+
+ if (out != 0) {
+ temp = size - 1;
+ ret = handler->input(out, &out_size, (const xmlChar *) in, &temp);
+ if (ret || temp - size + 1) {
+ if (ret) {
+ printf("ConvertInput: conversion wasn't successful.\n");
+ } else {
+ printf
+ ("ConvertInput: conversion wasn't successful. converted: %i octets.\n",
+ temp);
+ }
+
+ xmlFree(out);
+ out = 0;
+ } else {
+ out = (unsigned char *) xmlRealloc(out, out_size + 1);
+ out[out_size] = 0; /*null terminating out */
+ }
+ } else {
+ printf("ConvertInput: no mem\n");
+ }
+
+ return out;
+}
+
+#else
+int main(void) {
+ fprintf(stderr, "Writer or output support not compiled in\n");
+ exit(1);
+}
+#endif
diff --git a/doc/examples/tree1.c b/doc/examples/tree1.c
new file mode 100644
index 0000000..8a303e2
--- /dev/null
+++ b/doc/examples/tree1.c
@@ -0,0 +1,94 @@
+/**
+ * section: Tree
+ * synopsis: Navigates a tree to print element names
+ * purpose: Parse a file to a tree, use xmlDocGetRootElement() to
+ * get the root element, then walk the document and print
+ * all the element name in document order.
+ * usage: tree1 filename_or_URL
+ * test: tree1 test2.xml > tree1.tmp ; diff tree1.tmp tree1.res ; rm tree1.tmp
+ * author: Dodji Seketeli
+ * copy: see Copyright for the status of this software.
+ */
+#include <stdio.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+#ifdef LIBXML_TREE_ENABLED
+
+/*
+ *To compile this file using gcc you can type
+ *gcc `xml2-config --cflags --libs` -o xmlexample libxml2-example.c
+ */
+
+/**
+ * print_element_names:
+ * @a_node: the initial xml node to consider.
+ *
+ * Prints the names of the all the xml elements
+ * that are siblings or children of a given xml node.
+ */
+static void
+print_element_names(xmlNode * a_node)
+{
+ xmlNode *cur_node = NULL;
+
+ for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
+ if (cur_node->type == XML_ELEMENT_NODE) {
+ printf("node type: Element, name: %s\n", cur_node->name);
+ }
+
+ print_element_names(cur_node->children);
+ }
+}
+
+
+/**
+ * Simple example to parse a file called "file.xml",
+ * walk down the DOM, and print the name of the
+ * xml elements nodes.
+ */
+int
+main(int argc, char **argv)
+{
+ xmlDoc *doc = NULL;
+ xmlNode *root_element = NULL;
+
+ if (argc != 2)
+ return(1);
+
+ /*
+ * this initialize the library and check potential ABI mismatches
+ * between the version it was compiled for and the actual shared
+ * library used.
+ */
+ LIBXML_TEST_VERSION
+
+ /*parse the file and get the DOM */
+ doc = xmlParseFile(argv[1]);
+
+ if (doc == NULL) {
+ printf("error: could not parse file file.xml\n");
+ }
+
+ /*Get the root element node */
+ root_element = xmlDocGetRootElement(doc);
+
+ print_element_names(root_element);
+
+ /*free the document */
+ xmlFreeDoc(doc);
+
+ /*
+ *Free the global variables that may
+ *have been allocated by the parser.
+ */
+ xmlCleanupParser();
+
+ return 0;
+}
+#else
+int main(void) {
+ fprintf(stderr, "Tree support not compiled in\n");
+ exit(1);
+}
+#endif
diff --git a/doc/examples/tree1.res b/doc/examples/tree1.res
new file mode 100644
index 0000000..7b14ad0
--- /dev/null
+++ b/doc/examples/tree1.res
@@ -0,0 +1,4 @@
+node type: Element, name: doc
+node type: Element, name: src
+node type: Element, name: dest
+node type: Element, name: src
diff --git a/doc/examples/tree2.c b/doc/examples/tree2.c
new file mode 100644
index 0000000..3ab2179
--- /dev/null
+++ b/doc/examples/tree2.c
@@ -0,0 +1,118 @@
+/*
+ * section: Tree
+ * synopsis: Creates a tree
+ * purpose: Shows how to create document, nodes and dump it to stdout or file.
+ * usage: tree2 <filename> -Default output: stdout
+ * test: tree2 > tree2.tmp ; diff tree2.tmp tree2.res ; rm tree2.tmp
+ * author: Lucas Brasilino <brasilino@recife.pe.gov.br>
+ * copy: see Copyright for the status of this software
+ */
+
+#include <stdio.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+#ifdef LIBXML_TREE_ENABLED
+
+/*
+ *To compile this file using gcc you can type
+ *gcc `xml2-config --cflags --libs` -o tree2 tree2.c
+ */
+
+/* A simple example how to create DOM. Libxml2 automagically
+ * allocates the necessary amount of memory to it.
+*/
+int
+main(int argc, char **argv)
+{
+ xmlDocPtr doc = NULL; /* document pointer */
+ xmlNodePtr root_node = NULL, node = NULL, node1 = NULL;/* node pointers */
+ xmlDtdPtr dtd = NULL; /* DTD pointer */
+ char buff[256];
+ int i, j;
+
+ LIBXML_TEST_VERSION;
+
+ /*
+ * Creates a new document, a node and set it as a root node
+ */
+ doc = xmlNewDoc(BAD_CAST "1.0");
+ root_node = xmlNewNode(NULL, BAD_CAST "root");
+ xmlDocSetRootElement(doc, root_node);
+
+ /*
+ * Creates a DTD declaration. Isn't mandatory.
+ */
+ dtd = xmlCreateIntSubset(doc, BAD_CAST "root", NULL, BAD_CAST "tree2.dtd");
+
+ /*
+ * xmlNewChild() creates a new node, which is "attached" as child node
+ * of root_node node.
+ */
+ xmlNewChild(root_node, NULL, BAD_CAST "node1",
+ BAD_CAST "content of node 1");
+ /*
+ * The same as above, but the new child node doesn't have a content
+ */
+ xmlNewChild(root_node, NULL, BAD_CAST "node2", NULL);
+
+ /*
+ * xmlNewProp() creates attributes, which is "attached" to an node.
+ * It returns xmlAttrPtr, which isn't used here.
+ */
+ node =
+ xmlNewChild(root_node, NULL, BAD_CAST "node3",
+ BAD_CAST "this node has attributes");
+ xmlNewProp(node, BAD_CAST "attribute", BAD_CAST "yes");
+ xmlNewProp(node, BAD_CAST "foo", BAD_CAST "bar");
+
+ /*
+ * Here goes another way to create nodes. xmlNewNode() and xmlNewText
+ * creates a node and a text node separately. They are "attached"
+ * by xmlAddChild()
+ */
+ node = xmlNewNode(NULL, BAD_CAST "node4");
+ node1 = xmlNewText(BAD_CAST
+ "other way to create content (which is also a node)");
+ xmlAddChild(node, node1);
+ xmlAddChild(root_node, node);
+
+ /*
+ * A simple loop that "automates" nodes creation
+ */
+ for (i = 5; i < 7; i++) {
+ sprintf(buff, "node%d", i);
+ node = xmlNewChild(root_node, NULL, BAD_CAST buff, NULL);
+ for (j = 1; j < 4; j++) {
+ sprintf(buff, "node%d%d", i, j);
+ node1 = xmlNewChild(node, NULL, BAD_CAST buff, NULL);
+ xmlNewProp(node1, BAD_CAST "odd", BAD_CAST((j % 2) ? "no" : "yes"));
+ }
+ }
+
+ /*
+ * Dumping document to stdio or file
+ */
+ xmlSaveFormatFileEnc(argc > 1 ? argv[1] : "-", doc, "UTF-8", 1);
+
+ /*free the document */
+ xmlFreeDoc(doc);
+
+ /*
+ *Free the global variables that may
+ *have been allocated by the parser.
+ */
+ xmlCleanupParser();
+
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
+ return(0);
+}
+#else
+int main(void) {
+ fprintf(stderr, "tree support not compiled in\n");
+ exit(1);
+}
+#endif
diff --git a/doc/examples/tree2.res b/doc/examples/tree2.res
new file mode 100644
index 0000000..ed00195
--- /dev/null
+++ b/doc/examples/tree2.res
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE root SYSTEM "tree2.dtd">
+<root>
+ <node1>content of node 1</node1>
+ <node2/>
+ <node3 attribute="yes" foo="bar">this node has attributes</node3>
+ <node4>other way to create content (which is also a node)</node4>
+ <node5>
+ <node51 odd="no"/>
+ <node52 odd="yes"/>
+ <node53 odd="no"/>
+ </node5>
+ <node6>
+ <node61 odd="no"/>
+ <node62 odd="yes"/>
+ <node63 odd="no"/>
+ </node6>
+</root>
diff --git a/doc/examples/writer.xml b/doc/examples/writer.xml
new file mode 100644
index 0000000..6ab05fd
--- /dev/null
+++ b/doc/examples/writer.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<EXAMPLE><!--This is a comment with special chars: <äöü>--><ORDER version="1.0" xml:lang="de"><!--This is another comment with special chars: <äöü>--><HEADER><X_ORDER_ID>0000053535</X_ORDER_ID><CUSTOMER_ID>1010</CUSTOMER_ID><NAME_1>Müller</NAME_1><NAME_2>Jörg</NAME_2></HEADER><ENTRIES><ENTRY><ARTICLE>&lt;Test&gt;</ARTICLE><ENTRY_NO>10</ENTRY_NO></ENTRY><ENTRY><ARTICLE>&lt;Test 2&gt;</ARTICLE><ENTRY_NO>20</ENTRY_NO></ENTRY></ENTRIES><FOOTER><TEXT>This is a text.</TEXT></FOOTER></ORDER></EXAMPLE>
diff --git a/doc/examples/xpath1.c b/doc/examples/xpath1.c
new file mode 100644
index 0000000..0e49737
--- /dev/null
+++ b/doc/examples/xpath1.c
@@ -0,0 +1,249 @@
+/**
+ * section: XPath
+ * synopsis: Evaluate XPath expression and prints result node set.
+ * purpose: Shows how to evaluate XPath expression and register
+ * known namespaces in XPath context.
+ * usage: xpath1 <xml-file> <xpath-expr> [<known-ns-list>]
+ * author: Aleksey Sanin
+ * copy: see Copyright for the status of this software.
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include <libxml/tree.h>
+#include <libxml/parser.h>
+#include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
+
+#ifdef LIBXML_XPATH_ENABLED
+
+
+void usage(const char *name);
+int execute_xpath_expression(const char* filename, const xmlChar* xpathExpr, const xmlChar* nsList);
+int register_namespaces(xmlXPathContextPtr xpathCtx, const xmlChar* nsList);
+void print_xpath_nodes(xmlNodeSetPtr nodes, FILE* output);
+
+int
+main(int argc, char **argv) {
+ /* Parse command line and process file */
+ if((argc < 3) || (argc > 4)) {
+ fprintf(stderr, "Error: wrong number of arguments.\n");
+ usage(argv[0]);
+ return(-1);
+ }
+
+ /* Init libxml */
+ xmlInitParser();
+ LIBXML_TEST_VERSION
+
+ /* Do the main job */
+ if(execute_xpath_expression(argv[1], BAD_CAST argv[2], (argc > 3) ? BAD_CAST argv[3] : NULL) < 0) {
+ usage(argv[0]);
+ return(-1);
+ }
+
+ /* Shutdown libxml */
+ xmlCleanupParser();
+
+ /*
+ * this is to debug memory for regression tests
+ */
+ xmlMemoryDump();
+ return 0;
+}
+
+/**
+ * usage:
+ * @name: the program name.
+ *
+ * Prints usage information.
+ */
+void
+usage(const char *name) {
+ assert(name);
+
+ fprintf(stderr, "Usage: %s <xml-file> <xpath-expr> [<known-ns-list>]\n", name);
+ fprintf(stderr, "where <known-ns-list> is a list of known namespaces\n");
+ fprintf(stderr, "in \"<prefix1>=<href1> <prefix2>=href2> ...\" format\n");
+}
+
+/**
+ * execute_xpath_expression:
+ * @filename: the input XML filename.
+ * @xpathExpr: the xpath expression for evaluation.
+ * @nsList: the optional list of known namespaces in
+ * "<prefix1>=<href1> <prefix2>=href2> ..." format.
+ *
+ * Parses input XML file, evaluates XPath expression and prints results.
+ *
+ * Returns 0 on success and a negative value otherwise.
+ */
+int
+execute_xpath_expression(const char* filename, const xmlChar* xpathExpr, const xmlChar* nsList) {
+ xmlDocPtr doc;
+ xmlXPathContextPtr xpathCtx;
+ xmlXPathObjectPtr xpathObj;
+
+ assert(filename);
+ assert(xpathExpr);
+
+ /* Load XML document */
+ doc = xmlParseFile(filename);
+ if (doc == NULL) {
+ fprintf(stderr, "Error: unable to parse file \"%s\"\n", filename);
+ return(-1);
+ }
+
+ /* Create xpath evaluation context */
+ xpathCtx = xmlXPathNewContext(doc);
+ if(xpathCtx == NULL) {
+ fprintf(stderr,"Error: unable to create new XPath context\n");
+ xmlFreeDoc(doc);
+ return(-1);
+ }
+
+ /* Register namespaces from list (if any) */
+ if((nsList != NULL) && (register_namespaces(xpathCtx, nsList) < 0)) {
+ fprintf(stderr,"Error: failed to register namespaces list \"%s\"\n", nsList);
+ xmlXPathFreeContext(xpathCtx);
+ xmlFreeDoc(doc);
+ return(-1);
+ }
+
+ /* Evaluate xpath expression */
+ xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx);
+ if(xpathObj == NULL) {
+ fprintf(stderr,"Error: unable to evaluate xpath expression \"%s\"\n", xpathExpr);
+ xmlXPathFreeContext(xpathCtx);
+ xmlFreeDoc(doc);
+ return(-1);
+ }
+
+ /* Print results */
+ print_xpath_nodes(xpathObj->nodesetval, stdout);
+
+ /* Cleanup */
+ xmlXPathFreeObject(xpathObj);
+ xmlXPathFreeContext(xpathCtx);
+ xmlFreeDoc(doc);
+
+ return(0);
+}
+
+/**
+ * register_namespaces:
+ * @xpathCtx: the pointer to an XPath context.
+ * @nsList: the list of known namespaces in
+ * "<prefix1>=<href1> <prefix2>=href2> ..." format.
+ *
+ * Registers namespaces from @nsList in @xpathCtx.
+ *
+ * Returns 0 on success and a negative value otherwise.
+ */
+int
+register_namespaces(xmlXPathContextPtr xpathCtx, const xmlChar* nsList) {
+ xmlChar* nsListDup;
+ xmlChar* prefix;
+ xmlChar* href;
+ xmlChar* next;
+
+ assert(xpathCtx);
+ assert(nsList);
+
+ nsListDup = xmlStrdup(nsList);
+ if(nsListDup == NULL) {
+ fprintf(stderr, "Error: unable to strdup namespaces list\n");
+ return(-1);
+ }
+
+ next = nsListDup;
+ while(next != NULL) {
+ /* skip spaces */
+ while((*next) == ' ') next++;
+ if((*next) == '\0') break;
+
+ /* find prefix */
+ prefix = next;
+ next = (xmlChar*)xmlStrchr(next, '=');
+ if(next == NULL) {
+ fprintf(stderr,"Error: invalid namespaces list format\n");
+ xmlFree(nsListDup);
+ return(-1);
+ }
+ *(next++) = '\0';
+
+ /* find href */
+ href = next;
+ next = (xmlChar*)xmlStrchr(next, ' ');
+ if(next != NULL) {
+ *(next++) = '\0';
+ }
+
+ /* do register namespace */
+ if(xmlXPathRegisterNs(xpathCtx, prefix, href) != 0) {
+ fprintf(stderr,"Error: unable to register NS with prefix=\"%s\" and href=\"%s\"\n", prefix, href);
+ xmlFree(nsListDup);
+ return(-1);
+ }
+ }
+
+ xmlFree(nsListDup);
+ return(0);
+}
+
+/**
+ * print_xpath_nodes:
+ * @nodes: the nodes set.
+ * @output: the output file handle.
+ *
+ * Prints the @nodes content to @output.
+ */
+void
+print_xpath_nodes(xmlNodeSetPtr nodes, FILE* output) {
+ xmlNodePtr cur;
+ int size;
+ int i;
+
+ assert(output);
+ size = (nodes) ? nodes->nodeNr : 0;
+
+ fprintf(output, "Result (%d nodes):\n", size);
+ for(i = 0; i < size; ++i) {
+ assert(nodes->nodeTab[i]);
+
+ if(nodes->nodeTab[i]->type == XML_NAMESPACE_DECL) {
+ xmlNsPtr ns;
+
+ ns = (xmlNsPtr)nodes->nodeTab[i];
+ cur = (xmlNodePtr)ns->next;
+ if(cur->ns) {
+ fprintf(output, "= namespace \"%s\"=\"%s\" for node %s:%s\n",
+ ns->prefix, ns->href, cur->ns->href, cur->name);
+ } else {
+ fprintf(output, "= namespace \"%s\"=\"%s\" for node %s\n",
+ ns->prefix, ns->href, cur->name);
+ }
+ } else if(nodes->nodeTab[i]->type == XML_ELEMENT_NODE) {
+ cur = nodes->nodeTab[i];
+ if(cur->ns) {
+ fprintf(output, "= element node \"%s:%s\"\n",
+ cur->ns->href, cur->name);
+ } else {
+ fprintf(output, "= element node \"%s\"\n",
+ cur->name);
+ }
+ } else {
+ cur = nodes->nodeTab[i];
+ fprintf(output, "= node \"%s\": type %d\n", cur->name, cur->type);
+ }
+ }
+}
+
+#else
+int main(void) {
+ fprintf(stderr, "XPath support not compiled in\n");
+ exit(1);
+}
+#endif