From d381e5de4a8dc27983361d3ab3f45531cc5a2a6f Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Sun, 28 Apr 2024 21:14:32 +0200 Subject: [PATCH] doc: Move doc/examples to example --- .gitignore | 1 - .gitlab-ci.yml | 2 - Makefile.am | 1 - configure.ac | 2 +- doc/Makefile.am | 3 +- doc/examples/Makefile.am | 101 ---- doc/examples/examples.xml | 723 ------------------------- doc/examples/examples.xsl | 112 ---- doc/examples/index.html | 468 ---------------- doc/examples/index.py | 290 ---------- doc/examples/meson.build | 59 -- doc/meson.build | 1 - {doc/examples => example}/.gitignore | 1 + example/Makefile.am | 42 +- {doc/examples => example}/io1.c | 0 {doc/examples => example}/io2.c | 0 example/meson.build | 33 +- {doc/examples => example}/parse1.c | 0 {doc/examples => example}/parse2.c | 0 {doc/examples => example}/parse3.c | 0 {doc/examples => example}/parse4.c | 0 {doc/examples => example}/reader1.c | 0 {doc/examples => example}/reader2.c | 0 {doc/examples => example}/reader3.c | 0 {doc/examples => example}/reader4.c | 0 {doc/examples => example}/test1.xml | 0 {doc/examples => example}/test2.xml | 0 {doc/examples => example}/test3.xml | 0 {doc/examples => example}/testWriter.c | 0 {doc/examples => example}/tree1.c | 0 {doc/examples => example}/tree2.c | 0 {doc/examples => example}/xpath1.c | 0 {doc/examples => example}/xpath2.c | 0 33 files changed, 68 insertions(+), 1771 deletions(-) delete mode 100644 doc/examples/Makefile.am delete mode 100644 doc/examples/examples.xml delete mode 100644 doc/examples/examples.xsl delete mode 100644 doc/examples/index.html delete mode 100755 doc/examples/index.py delete mode 100644 doc/examples/meson.build rename {doc/examples => example}/.gitignore (92%) rename {doc/examples => example}/io1.c (100%) rename {doc/examples => example}/io2.c (100%) rename {doc/examples => example}/parse1.c (100%) rename {doc/examples => example}/parse2.c (100%) rename {doc/examples => example}/parse3.c (100%) rename {doc/examples => example}/parse4.c (100%) rename {doc/examples => example}/reader1.c (100%) rename {doc/examples => example}/reader2.c (100%) rename {doc/examples => example}/reader3.c (100%) rename {doc/examples => example}/reader4.c (100%) rename {doc/examples => example}/test1.xml (100%) rename {doc/examples => example}/test2.xml (100%) rename {doc/examples => example}/test3.xml (100%) rename {doc/examples => example}/testWriter.c (100%) rename {doc/examples => example}/tree1.c (100%) rename {doc/examples => example}/tree2.c (100%) rename {doc/examples => example}/xpath1.c (100%) rename {doc/examples => example}/xpath2.c (100%) diff --git a/.gitignore b/.gitignore index 55667111..4b2f754d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ *.pyc # Executables -/example/gjobread /xmlcatalog /xmllint diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7fb9c8c2..a4e8c0ea 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -290,8 +290,6 @@ pages: script: - mkdir -p public - cp -r doc/devhelp doc/tutorial doc/xmllint.html doc/xmlcatalog.html public - - mkdir -p public/examples - - cp doc/examples/*.html doc/examples/*.c public/examples artifacts: paths: - public diff --git a/Makefile.am b/Makefile.am index 3e8de7b8..727185e4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -380,7 +380,6 @@ DISTCLEANFILES = COPYING missing.lst EXTRA_DIST = Copyright check-xml-test-suite.py gentest.py \ check-relaxng-test-suite.py check-relaxng-test-suite2.py \ check-xsddata-test-suite.py check-xinclude-test-suite.py \ - example/Makefile.am example/gjobread.c example/gjobs.xml \ libxml2-config.cmake.in autogen.sh \ libxml.h \ genUnicode.py \ diff --git a/configure.ac b/configure.ac index 6d05f6c7..fc0a9b3d 100644 --- a/configure.ac +++ b/configure.ac @@ -1158,7 +1158,7 @@ RELDATE=`date +'%a %b %e %Y'` AC_SUBST(RELDATE) # keep on one line for cygwin c.f. #130896 -AC_CONFIG_FILES([Makefile include/Makefile include/libxml/Makefile include/private/Makefile doc/Makefile doc/examples/Makefile doc/devhelp/Makefile example/Makefile fuzz/Makefile python/Makefile python/tests/Makefile xstc/Makefile include/libxml/xmlversion.h libxml-2.0.pc libxml-2.0-uninstalled.pc libxml2-config.cmake]) +AC_CONFIG_FILES([Makefile include/Makefile include/libxml/Makefile include/private/Makefile doc/Makefile doc/devhelp/Makefile example/Makefile fuzz/Makefile python/Makefile python/tests/Makefile xstc/Makefile include/libxml/xmlversion.h libxml-2.0.pc libxml-2.0-uninstalled.pc libxml2-config.cmake]) AC_CONFIG_FILES([python/setup.py], [chmod +x python/setup.py]) AC_CONFIG_FILES([xml2-config], [chmod +x xml2-config]) AC_OUTPUT diff --git a/doc/Makefile.am b/doc/Makefile.am index 1b992417..577bb34a 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -1,5 +1,5 @@ ## Process this file with automake to produce Makefile.in -SUBDIRS = . devhelp examples +SUBDIRS = . devhelp nobase_dist_doc_DATA = \ tutorial/apa.html \ @@ -72,7 +72,6 @@ rebuild: cd $(srcdir) && $(XSLTPROC) --nonet xmlcatalog.xml cd $(srcdir) && $(XSLTPROC) --nonet -o xmlcatalog.html $(DOCBOOK_HTML) xmlcatalog.xml cd devhelp && $(MAKE) rebuild - cd examples && $(MAKE) rebuild cd .. && $(MAKE) rebuild_testapi .PHONY: rebuild diff --git a/doc/examples/Makefile.am b/doc/examples/Makefile.am deleted file mode 100644 index 3b82da6b..00000000 --- a/doc/examples/Makefile.am +++ /dev/null @@ -1,101 +0,0 @@ -AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -LDADD = $(top_builddir)/libxml2.la - -rebuild: - cd $(srcdir) && $(PYTHON) index.py - $(MAKE) Makefile - cd $(srcdir) && xsltproc examples.xsl examples.xml - -cd $(srcdir) && xmllint --valid --noout index.html - -.PHONY: rebuild - -install-data-local: - $(MKDIR_P) $(DESTDIR)$(docdir)/examples - -$(INSTALL) -m 0644 $(srcdir)/*.html $(srcdir)/*.c $(DESTDIR)$(docdir)/examples/ - -uninstall-local: - rm -f $(DESTDIR)$(docdir)/examples/*.c - rm -f $(DESTDIR)$(docdir)/examples/*.html - -rmdir $(DESTDIR)$(docdir)/examples - -clean-local: - test -f Makefile.am || rm -f test?.xml - -EXTRA_DIST = \ - examples.xml \ - examples.xsl \ - index.html \ - index.py \ - test1.xml \ - test2.xml \ - test3.xml \ - meson.build - -check_PROGRAMS = \ - io1 \ - io2 \ - parse1 \ - parse2 \ - parse3 \ - parse4 \ - reader1 \ - reader2 \ - reader3 \ - reader4 \ - testWriter \ - tree1 \ - tree2 \ - xpath1 \ - xpath2 - -io1_SOURCES = io1.c - -io2_SOURCES = io2.c - -parse1_SOURCES = parse1.c - -parse2_SOURCES = parse2.c - -parse3_SOURCES = parse3.c - -parse4_SOURCES = parse4.c - -reader1_SOURCES = reader1.c - -reader2_SOURCES = reader2.c - -reader3_SOURCES = reader3.c - -reader4_SOURCES = reader4.c - -testWriter_SOURCES = testWriter.c - -tree1_SOURCES = tree1.c - -tree2_SOURCES = tree2.c - -xpath1_SOURCES = xpath1.c - -xpath2_SOURCES = xpath2.c - -valgrind: - $(MAKE) CHECKER='valgrind' check - -check-local: - @test -f Makefile.am || test -f test1.xml || $(LN_S) $(srcdir)/test?.xml . - @(echo '## examples regression tests') - @$(CHECKER) ./io1 >/dev/null - @$(CHECKER) ./io2 >/dev/null - @$(CHECKER) ./parse1 test1.xml - @$(CHECKER) ./parse2 test2.xml - @$(CHECKER) ./parse3 - @$(CHECKER) ./parse4 test3.xml - @$(CHECKER) ./reader1 test2.xml >/dev/null - @$(CHECKER) ./reader2 test2.xml >/dev/null - @$(CHECKER) ./reader3 >/dev/null - @$(CHECKER) ./reader4 test1.xml test2.xml test3.xml >/dev/null - @$(CHECKER) ./testWriter - @$(CHECKER) ./tree1 test2.xml >/dev/null - @$(CHECKER) ./tree2 >/dev/null - @$(CHECKER) ./xpath1 test3.xml '//child2' >/dev/null - @$(CHECKER) ./xpath2 test3.xml '//discarded' discarded >/dev/null diff --git a/doc/examples/examples.xml b/doc/examples/examples.xml deleted file mode 100644 index 0cf0f2b8..00000000 --- a/doc/examples/examples.xml +++ /dev/null @@ -1,723 +0,0 @@ - - - Example of custom Input/Output - 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. - io1 - io1 > io1.tmp && diff io1.tmp $(srcdir)/io1.res - Daniel Veillard - see Copyright for the status of this software. -
InputOutput
- - <libxml/parser.h> - <libxml/tree.h> - <libxml/xinclude.h> - <libxml/xmlIO.h> - - - - - - - - - - -
- - Output to char buffer - Demonstrate the use of xmlDocDumpMemory to output document to a character buffer - io2 - io2 > io2.tmp && diff io2.tmp $(srcdir)/io2.res - John Fleck - see Copyright for the status of this software. -
InputOutput
- - <libxml/parser.h> - - - - - - - - - - - - -
- - Parse an XML file to a tree and free it - Demonstrate the use of xmlReadFile() to read an XML file into a tree and xmlFreeDoc() to free the resulting tree - parse1 test1.xml - parse1 test1.xml - Daniel Veillard - see Copyright for the status of this software. -
Parsing
- - <libxml/parser.h> - <libxml/tree.h> - - - - - - - -
- - Parse and validate an XML file to a tree and free the result - 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. - parse2 test2.xml - parse2 test2.xml - Daniel Veillard - see Copyright for the status of this software. -
Parsing
- - <libxml/parser.h> - <libxml/tree.h> - - - - - - - - - - - -
- - Parse an XML document in memory to a tree and free it - Demonstrate the use of xmlReadMemory() to read an XML file into a tree and xmlFreeDoc() to free the resulting tree - parse3 - parse3 - Daniel Veillard - see Copyright for the status of this software. -
Parsing
- - <libxml/parser.h> - <libxml/tree.h> - - - - - - - -
- - Parse an XML document chunk by chunk to a tree and free it - Demonstrate the use of xmlCreatePushParserCtxt() and xmlParseChunk() to read an XML file progressively into a tree and xmlFreeDoc() to free the resulting tree - parse4 test3.xml - parse4 test3.xml - Daniel Veillard - see Copyright for the status of this software. -
Parsing
- - <libxml/parser.h> - <libxml/tree.h> - - - - - - - - - - -
- - Parse an XML file with an xmlReader - Demonstrate the use of xmlReaderForFile() to parse an XML file and dump the information about the nodes found in the process. (Note that the XMLReader functions require libxml2 version later than 2.6.) - reader1 <filename> - reader1 test2.xml > reader1.tmp && diff reader1.tmp $(srcdir)/reader1.res - Daniel Veillard - see Copyright for the status of this software. -
xmlReader
- - <libxml/xmlreader.h> - - - - - - - - - - - - - - - -
- - Parse and validate an XML file with an xmlReader - 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.) - reader2 <valid_xml_filename> - reader2 test2.xml > reader1.tmp && diff reader1.tmp $(srcdir)/reader1.res - Daniel Veillard - see Copyright for the status of this software. -
xmlReader
- - <libxml/parser.h> - <libxml/xmlreader.h> - - - - - - - - - - - - - - - - - - -
- - Show how to extract subdocuments with xmlReader - 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.) - reader3 - reader3 > reader3.tmp && diff reader3.tmp $(srcdir)/reader3.res - Daniel Veillard - see Copyright for the status of this software. -
xmlReader
- - <libxml/xmlreader.h> - - - - - - - - - - -
- - Parse multiple XML files reusing an xmlReader - Demonstrate the use of xmlReaderForFile() and xmlReaderNewFile to parse XML files while reusing the reader object and parser context. (Note that the XMLReader functions require libxml2 version later than 2.6.) - reader4 <filename> [ filename ... ] - reader4 test1.xml test2.xml test3.xml > reader4.tmp && diff reader4.tmp $(srcdir)/reader4.res - Graham Bennett - see Copyright for the status of this software. -
xmlReader
- - <libxml/xmlreader.h> - - - - - - - - - -
- - use various APIs for the xmlWriter - 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. - testWriter - testWriter && for i in 1 2 3 4 ; do diff $(srcdir)/writer.xml writer$$i.tmp || break ; done - Alfred Mickautsch - see Copyright for the status of this software. -
xmlWriter
- - <libxml/encoding.h> - <libxml/parser.h> - <libxml/xmlwriter.h> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - Navigates a tree to print element names - 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. - tree1 filename_or_URL - tree1 test2.xml > tree1.tmp && diff tree1.tmp $(srcdir)/tree1.res - Dodji Seketeli - see Copyright for the status of this software. -
Tree
- - <libxml/parser.h> - <libxml/tree.h> - - - - - - -
- - Creates a tree - Shows how to create document, nodes and dump it to stdout or file. - tree2 <filename> -Default output: stdout - tree2 > tree2.tmp && diff tree2.tmp $(srcdir)/tree2.res - Lucas Brasilino <brasilino@recife.pe.gov.br> - see Copyright for the status of this software -
Tree
- - <libxml/parser.h> - <libxml/tree.h> - - - - - - - - - - - - -
- - Evaluate XPath expression and prints result node set. - Shows how to evaluate XPath expression and register known namespaces in XPath context. - xpath1 <xml-file> <xpath-expr> [<known-ns-list>] - xpath1 test3.xml '//child2' > xpath1.tmp && diff xpath1.tmp $(srcdir)/xpath1.res - Aleksey Sanin - see Copyright for the status of this software. -
XPath
- - <libxml/parser.h> - <libxml/tree.h> - <libxml/xpath.h> - <libxml/xpathInternals.h> - - - - - - - - - - - - - - - - - - - -
- - Load a document, locate subelements with XPath, modify said elements and save the resulting document. - Shows how to make a full round-trip from a load/edit/save - xpath2 <xml-file> <xpath-expr> <new-value> - xpath2 test3.xml '//discarded' discarded > xpath2.tmp && diff xpath2.tmp $(srcdir)/xpath2.res - Aleksey Sanin and Daniel Veillard - see Copyright for the status of this software. -
XPath
- - <libxml/parser.h> - <libxml/tree.h> - <libxml/xpath.h> - <libxml/xpathInternals.h> - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
-
- - - - -
-
- - -
-
- - -
-
- - - - -
-
- -
-
-
diff --git a/doc/examples/examples.xsl b/doc/examples/examples.xsl deleted file mode 100644 index c515408d..00000000 --- a/doc/examples/examples.xsl +++ /dev/null @@ -1,112 +0,0 @@ - - - - https://gnome.pages.gitlab.gnome.org/libxml2/devhelp/libxml2- - - - - -
  • -
    - - - - - -
  • line : Type from
  • -
    - - - - - -
  • line : Function from
  • -
    - - - - - -
  • line : Macro from
  • -
    - - - -

    :

    -

    -

    Includes:

    -
      - - - - -
    -

    Uses:

    -
      - - - - -
    -

    Usage:

    -

    -

    Author:

    -
    - - -
  • :

    -
      - - - -
    • :
    • -
      -
    -
  • -
    - - -

    The examples are stored per section depending on the main focus - of the example:

    -
      - - - - -
    -

    Getting the compilation options and libraries dependencies needed -to generate binaries from the examples is best done on Linux/Unix by using -the xml2-config script which should have been installed as part of make -install step or when installing the libxml2 development package:

    -
    gcc -o example `xml2-config --cflags` example.c `xml2-config --libs`
    -
    - - - - -

    Examples

    - -
    -
    - - - Libxml2 set of examples - - - - - <xsl:value-of select="$title"/> - - - -

    - - - - -
    -
    - -
    diff --git a/doc/examples/index.html b/doc/examples/index.html deleted file mode 100644 index 14694030..00000000 --- a/doc/examples/index.html +++ /dev/null @@ -1,468 +0,0 @@ - - - - - Libxml2 set of examples - - -

    Libxml2 set of examples

    -

    The examples are stored per section depending on the main focus - of the example:

    - -

    Getting the compilation options and libraries dependencies needed -to generate binaries from the examples is best done on Linux/Unix by using -the xml2-config script which should have been installed as part of make -install step or when installing the libxml2 development package:

    -
    gcc -o example `xml2-config --cflags` example.c `xml2-config --libs`
    -

    InputOutput Examples

    -

    io1.c: Example of custom Input/Output

    -

    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.

    -

    Includes:

    - -

    Uses:

    - -

    Usage:

    -

    io1

    -

    Author: Daniel Veillard

    -

    io2.c: Output to char buffer

    -

    Demonstrate the use of xmlDocDumpMemory to output document to a character buffer

    -

    Includes:

    - -

    Uses:

    - -

    Usage:

    -

    io2

    -

    Author: John Fleck

    -

    Parsing Examples

    -

    parse1.c: Parse an XML file to a tree and free it

    -

    Demonstrate the use of xmlReadFile() to read an XML file into a tree and xmlFreeDoc() to free the resulting tree

    -

    Includes:

    - -

    Uses:

    - -

    Usage:

    -

    parse1 test1.xml

    -

    Author: Daniel Veillard

    -

    parse2.c: Parse and validate an XML file to a tree and free the result

    -

    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.

    -

    Includes:

    - -

    Uses:

    - -

    Usage:

    -

    parse2 test2.xml

    -

    Author: Daniel Veillard

    -

    parse3.c: Parse an XML document in memory to a tree and free it

    -

    Demonstrate the use of xmlReadMemory() to read an XML file into a tree and xmlFreeDoc() to free the resulting tree

    -

    Includes:

    - -

    Uses:

    - -

    Usage:

    -

    parse3

    -

    Author: Daniel Veillard

    -

    parse4.c: Parse an XML document chunk by chunk to a tree and free it

    -

    Demonstrate the use of xmlCreatePushParserCtxt() and xmlParseChunk() to read an XML file progressively into a tree and xmlFreeDoc() to free the resulting tree

    -

    Includes:

    - -

    Uses:

    - -

    Usage:

    -

    parse4 test3.xml

    -

    Author: Daniel Veillard

    -

    Tree Examples

    -

    tree1.c: Navigates a tree to print element names

    -

    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.

    -

    Includes:

    - -

    Uses:

    - -

    Usage:

    -

    tree1 filename_or_URL

    -

    Author: Dodji Seketeli

    -

    tree2.c: Creates a tree

    -

    Shows how to create document, nodes and dump it to stdout or file.

    -

    Includes:

    - -

    Uses:

    - -

    Usage:

    -

    tree2 <filename> -Default output: stdout

    -

    Author: Lucas Brasilino <brasilino@recife.pe.gov.br>

    -

    XPath Examples

    -

    xpath1.c: Evaluate XPath expression and prints result node set.

    -

    Shows how to evaluate XPath expression and register known namespaces in XPath context.

    -

    Includes:

    - -

    Uses:

    - -

    Usage:

    -

    xpath1 <xml-file> <xpath-expr> [<known-ns-list>]

    -

    Author: Aleksey Sanin

    -

    xpath2.c: Load a document, locate subelements with XPath, modify said elements and save the resulting document.

    -

    Shows how to make a full round-trip from a load/edit/save

    -

    Includes:

    - -

    Uses:

    - -

    Usage:

    -

    xpath2 <xml-file> <xpath-expr> <new-value>

    -

    Author: Aleksey Sanin and Daniel Veillard

    -

    xmlReader Examples

    -

    reader1.c: Parse an XML file with an xmlReader

    -

    Demonstrate the use of xmlReaderForFile() to parse an XML file and dump the information about the nodes found in the process. (Note that the XMLReader functions require libxml2 version later than 2.6.)

    -

    Includes:

    - -

    Uses:

    - -

    Usage:

    -

    reader1 <filename>

    -

    Author: Daniel Veillard

    -

    reader2.c: Parse and validate an XML file with an xmlReader

    -

    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.)

    -

    Includes:

    - -

    Uses:

    - -

    Usage:

    -

    reader2 <valid_xml_filename>

    -

    Author: Daniel Veillard

    -

    reader3.c: Show how to extract subdocuments with xmlReader

    -

    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.)

    -

    Includes:

    - -

    Uses:

    - -

    Usage:

    -

    reader3

    -

    Author: Daniel Veillard

    -

    reader4.c: Parse multiple XML files reusing an xmlReader

    -

    Demonstrate the use of xmlReaderForFile() and xmlReaderNewFile to parse XML files while reusing the reader object and parser context. (Note that the XMLReader functions require libxml2 version later than 2.6.)

    -

    Includes:

    - -

    Uses:

    - -

    Usage:

    -

    reader4 <filename> [ filename ... ]

    -

    Author: Graham Bennett

    -

    xmlWriter Examples

    -

    testWriter.c: use various APIs for the xmlWriter

    -

    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.

    -

    Includes:

    - -

    Uses:

    - -

    Usage:

    -

    testWriter

    -

    Author: Alfred Mickautsch

    - - diff --git a/doc/examples/index.py b/doc/examples/index.py deleted file mode 100755 index bceae8b9..00000000 --- a/doc/examples/index.py +++ /dev/null @@ -1,290 +0,0 @@ -#!/usr/bin/env python3 -# -# Indexes the examples and build an XML description -# -import glob -import sys -try: - import libxml2 -except: - print("libxml2 python bindings not available") - sys.exit(1) -sys.path.insert(0, "..") -from apibuild import CParser, escape - -examples = [] -extras = ['examples.xsl', 'index.html', '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 name in api_dict: - 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 = comment.split("\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) = line.split(":", 1) - item = it - while line != "" and (line[0] == ' ' or line[0] == '\t'): - line = line[1:] - if item in res: - res[item] = res[item] + " " + line - else: - res[item] = line - except: - if item != None: - if item in res: - 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(" \n" % filename) - try: - synopsis = info['synopsis'] - output.write(" %s\n" % escape(synopsis)); - except: - print("Example %s lacks a synopsis description" % (filename)) - try: - purpose = info['purpose'] - output.write(" %s\n" % escape(purpose)); - except: - print("Example %s lacks a purpose description" % (filename)) - try: - usage = info['usage'] - output.write(" %s\n" % escape(usage)); - except: - print("Example %s lacks an usage description" % (filename)) - try: - test = info['test'] - output.write(" %s\n" % escape(test)); - progname=filename[0:-2] - command=test.replace(progname, './' + progname, 1) - tests.append(command) - except: - pass - try: - author = info['author'] - output.write(" %s\n" % escape(author)); - except: - print("Example %s lacks an author description" % (filename)) - try: - copy = info['copy'] - output.write(" %s\n" % escape(copy)); - except: - print("Example %s lacks a copyright description" % (filename)) - try: - section = info['section'] - output.write("
    %s
    \n" % escape(section)); - if section in sections: - sections[section].append(filename) - else: - sections[section] = [filename] - except: - print("Example %s lacks a section description" % (filename)) - for topic in sorted(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(" %s\n" % ( - escape(topic), escape(str))) - output.write(" \n") - for include in sorted(idx.includes.keys()): - if include.find("libxml") != -1: - id = idx.includes[include] - line = id.get_lineno() - output.write(" %s\n" % - (line, escape(include))) - output.write(" \n") - output.write(" \n") - for ref in sorted(idx.references.keys()): - id = idx.references[ref] - name = id.get_name() - line = id.get_lineno() - if name in symbols: - 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(" \n") - output.write("
    \n") - - return idx - -def dump_symbols(output): - global symbols - - output.write(" \n") - for symbol in sorted(symbols.keys()): - output.write(" \n" % (symbol)) - info = symbols[symbol] - i = 1 - while i < len(info): - output.write(" \n" % (info[i])) - i = i + 1 - output.write(" \n") - output.write(" \n") - -def dump_sections(output): - global sections - - output.write(" \n") - for section in sorted(sections.keys()): - output.write("
    \n" % (section)) - info = sections[section] - i = 0 - while i < len(info): - output.write(" \n" % (info[i])) - i = i + 1 - output.write("
    \n") - output.write("
    \n") - -def dump_Makefile(): - for file in glob.glob('*.xml'): - extras.append(file) - for file in glob.glob('*.res'): - extras.append(file) - Makefile="""## -## This file is auto-generated by index.py -## DO NOT EDIT !!! -## - -AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -LDADD = $(top_builddir)/libxml2.la - -CLEANFILES = *.tmp - -rebuild: -\tcd $(srcdir) && $(PYTHON) index.py -\t$(MAKE) Makefile -\tcd $(srcdir) && xsltproc examples.xsl examples.xml -\t-cd $(srcdir) && xmllint --valid --noout index.html - -.PHONY: rebuild - -install-data-local: -\t$(MKDIR_P) $(DESTDIR)$(docdir)/examples -\t-$(INSTALL) -m 0644 $(srcdir)/*.html $(srcdir)/*.c $(DESTDIR)$(docdir)/examples/ - -clean-local: -\ttest -f Makefile.am || rm -f test?.xml - -""" - examples.sort() - extras.sort() - tests.sort() - EXTRA_DIST="" - for extra in extras: - EXTRA_DIST = EXTRA_DIST + " \\\n\t" + extra - Makefile = Makefile + "EXTRA_DIST =%s\n\n" % (EXTRA_DIST) - check_PROGRAMS="" - for example in examples: - check_PROGRAMS = check_PROGRAMS + " \\\n\t" + example - Makefile = Makefile + "check_PROGRAMS =%s\n\n" % (check_PROGRAMS) - for example in examples: - Makefile = Makefile + "%s_SOURCES = %s.c\n\n" % (example, example) - Makefile = Makefile + "valgrind: \n\t$(MAKE) CHECKER='valgrind' tests\n\n" - Makefile = Makefile + "tests: $(check_PROGRAMS)\n" - Makefile = Makefile + "\t@test -f Makefile.am || test -f test1.xml || $(LN_S) $(srcdir)/test?.xml .\n" - Makefile = Makefile + "\t@(echo '## examples regression tests')\n" - for test in tests: - Makefile = Makefile + "\t@$(CHECKER) %s\n" % (test) - Makefile = Makefile + "\t@rm *.tmp\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") - -if __name__ == "__main__": - load_api() - output = open("examples.xml", "w") - output.write("\n") - - for file in sorted(glob.glob('*.c')): - parse(file, output) - examples.append(file[:-2]) - - dump_symbols(output) - dump_sections(output) - output.write("\n") - output.close() - #dump_Makefile() - diff --git a/doc/examples/meson.build b/doc/examples/meson.build deleted file mode 100644 index 3ce8f520..00000000 --- a/doc/examples/meson.build +++ /dev/null @@ -1,59 +0,0 @@ - -## tests - -example_checks = [ - ['io1', ''], - ['io2', ''], - ['parse1', 'test1.xml'], - ['parse2', 'test2.xml'], - ['parse3', ''], - ['parse4', 'test3.xml'], - ['reader1', 'test2.xml'], - ['reader2', 'test2.xml'], - ['reader3', ''], - ['reader4', ['test1.xml', 'test2.xml', 'test3.xml']], - ['testWriter', ''], - ['tree1', 'test2.xml'], - ['tree2', ''], - ['xpath1', ['test3.xml', '//child2']], - ['xpath2', ['test3.xml', '//discarded', 'discarded']], -] - -foreach check : example_checks - exe = executable( - check[0], - files(check[0] + '.c'), - dependencies: xml_dep, - include_directories: config_dir, - ) - test( - check[0], - exe, - args: check[1], - timeout: 0, - workdir: meson.current_source_dir(), - ) -endforeach - -## example files - -example_files = files( - 'index.html', - 'io1.c', - 'io2.c', - 'parse1.c', - 'parse2.c', - 'parse3.c', - 'parse4.c', - 'reader1.c', - 'reader2.c', - 'reader3.c', - 'reader4.c', - 'testWriter.c', - 'tree1.c', - 'tree2.c', - 'xpath1.c', - 'xpath2.c', -) - -install_data(example_files, install_dir: dir_doc / 'examples') diff --git a/doc/meson.build b/doc/meson.build index 8a2c3462..cf8e8793 100644 --- a/doc/meson.build +++ b/doc/meson.build @@ -10,5 +10,4 @@ tutorial_files = files( install_data(tutorial_files, install_dir: dir_doc) subdir('devhelp') -subdir('examples') subdir('tutorial') diff --git a/doc/examples/.gitignore b/example/.gitignore similarity index 92% rename from doc/examples/.gitignore rename to example/.gitignore index ec244f23..04c5cb3b 100644 --- a/doc/examples/.gitignore +++ b/example/.gitignore @@ -1,3 +1,4 @@ +/gjobread /io1 /io2 /parse1 diff --git a/example/Makefile.am b/example/Makefile.am index 0f6fb58b..791764fa 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -1,8 +1,44 @@ -check_PROGRAMS = gjobread +EXTRA_DIST = \ + gjobs.xml \ + meson.build \ + test1.xml \ + test2.xml \ + test3.xml + +check_PROGRAMS = \ + gjobread \ + io1 \ + io2 \ + parse1 \ + parse2 \ + parse3 \ + parse4 \ + reader1 \ + reader2 \ + reader3 \ + reader4 \ + testWriter \ + tree1 \ + tree2 \ + xpath1 \ + xpath2 AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include LDADD = $(top_builddir)/libxml2.la gjobread_SOURCES=gjobread.c - -EXTRA_DIST = meson.build +io1_SOURCES = io1.c +io2_SOURCES = io2.c +parse1_SOURCES = parse1.c +parse2_SOURCES = parse2.c +parse3_SOURCES = parse3.c +parse4_SOURCES = parse4.c +reader1_SOURCES = reader1.c +reader2_SOURCES = reader2.c +reader3_SOURCES = reader3.c +reader4_SOURCES = reader4.c +testWriter_SOURCES = testWriter.c +tree1_SOURCES = tree1.c +tree2_SOURCES = tree2.c +xpath1_SOURCES = xpath1.c +xpath2_SOURCES = xpath2.c diff --git a/doc/examples/io1.c b/example/io1.c similarity index 100% rename from doc/examples/io1.c rename to example/io1.c diff --git a/doc/examples/io2.c b/example/io2.c similarity index 100% rename from doc/examples/io2.c rename to example/io2.c diff --git a/example/meson.build b/example/meson.build index d95e5aff..b6515ab4 100644 --- a/example/meson.build +++ b/example/meson.build @@ -1,8 +1,27 @@ - -exe = executable( +examples = [ 'gjobread', - files('gjobread.c'), - dependencies: xml_dep, - include_directories: config_dir, -) -test('gjobread', exe, timeout: 0) + 'io1', + 'io2', + 'parse1', + 'parse2', + 'parse3', + 'parse4', + 'reader1', + 'reader2', + 'reader3', + 'reader4', + 'testWriter', + 'tree1', + 'tree2', + 'xpath1', + 'xpath2', +] + +foreach example : examples + exe = executable( + example, + files(example + '.c'), + dependencies: xml_dep, + include_directories: config_dir, + ) +endforeach diff --git a/doc/examples/parse1.c b/example/parse1.c similarity index 100% rename from doc/examples/parse1.c rename to example/parse1.c diff --git a/doc/examples/parse2.c b/example/parse2.c similarity index 100% rename from doc/examples/parse2.c rename to example/parse2.c diff --git a/doc/examples/parse3.c b/example/parse3.c similarity index 100% rename from doc/examples/parse3.c rename to example/parse3.c diff --git a/doc/examples/parse4.c b/example/parse4.c similarity index 100% rename from doc/examples/parse4.c rename to example/parse4.c diff --git a/doc/examples/reader1.c b/example/reader1.c similarity index 100% rename from doc/examples/reader1.c rename to example/reader1.c diff --git a/doc/examples/reader2.c b/example/reader2.c similarity index 100% rename from doc/examples/reader2.c rename to example/reader2.c diff --git a/doc/examples/reader3.c b/example/reader3.c similarity index 100% rename from doc/examples/reader3.c rename to example/reader3.c diff --git a/doc/examples/reader4.c b/example/reader4.c similarity index 100% rename from doc/examples/reader4.c rename to example/reader4.c diff --git a/doc/examples/test1.xml b/example/test1.xml similarity index 100% rename from doc/examples/test1.xml rename to example/test1.xml diff --git a/doc/examples/test2.xml b/example/test2.xml similarity index 100% rename from doc/examples/test2.xml rename to example/test2.xml diff --git a/doc/examples/test3.xml b/example/test3.xml similarity index 100% rename from doc/examples/test3.xml rename to example/test3.xml diff --git a/doc/examples/testWriter.c b/example/testWriter.c similarity index 100% rename from doc/examples/testWriter.c rename to example/testWriter.c diff --git a/doc/examples/tree1.c b/example/tree1.c similarity index 100% rename from doc/examples/tree1.c rename to example/tree1.c diff --git a/doc/examples/tree2.c b/example/tree2.c similarity index 100% rename from doc/examples/tree2.c rename to example/tree2.c diff --git a/doc/examples/xpath1.c b/example/xpath1.c similarity index 100% rename from doc/examples/xpath1.c rename to example/xpath1.c diff --git a/doc/examples/xpath2.c b/example/xpath2.c similarity index 100% rename from doc/examples/xpath2.c rename to example/xpath2.c