From c230410eadbada15092c04f92d01068af8a19f8d Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Thu, 29 Jun 2000 00:43:27 +0000 Subject: [PATCH] 2.1.0 test release for good, updated doc and example, Daniel. --- doc/upgrade.html | 90 ++++++++++++++++++++-------------------------- example/gjobread.c | 1 + 2 files changed, 39 insertions(+), 52 deletions(-) diff --git a/doc/upgrade.html b/doc/upgrade.html index b261c0f4..e7013ba1 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -3,7 +3,7 @@ Upgrading libxml client code from 1.x to 2.x - + @@ -48,17 +48,7 @@ mail:

Use xmlDocGetRootElement(doc) to get the root element of a document. Alternatively if you are sure to not reference Dtds nor have PIs or comments before or after the root element s/->root/->children/g - will probably do it. -

Note: libxml2 final version now export a version - number as the LIBXML_VERSION preprocessor token. In most case the changes - required for 1/ and 2/ can be dealt with using the following construct (if - you don't use root identifier for other purposes):

-
#if defined(LIBXML_VERSION) && LIBXML_VERSION >= 20000
-#define root children
-#define childs children
-#endif
-    
- + will probably do it.
  • The white space issue, this one is more complex, unless special case of validating parsing, the line breaks and spaces usually used for indenting and formatting the document content becomes significant. So they are @@ -90,49 +80,45 @@ mail:

  • -

    Keeping both libxml-1.x and libxml-2.x compatibility:

    +

    Ensuring both libxml-1.x and libxml-2.x compatibility

    -

    Here is the steps i applied successfully to a couple of gnome project -dependant on libxml to allow compilation under both environments:

    +

    Two new version of libxml (1.8.8) and libxml2 (2.1.0) have been released to +allow smoth upgrade of existing libxml v1code while retaining compatibility. +They offers the following:

      -
    1. make sure your configure adds the output of "xml-config --cflags" to - the compiler command line
    2. -
    3. in your C files including libxml includes do the following -
      #include <xmlmemory.h>
      -#if defined(LIBXML_VERSION) && LIBXML_VERSION >= 20000
      -#include <libxml/parser.h>
      -#include <libxml/tree.h>
      -#define root children
      -#define childs children
      -#else 
      -#include <gnome-xml/parser.h>
      -#include <gnome-xml/tree.h>
      -#endif
      -

      the first include name is really specific to libxml and won't clash - with other installed softare includes. Once included we can tell - the version used and use prefixed path for the includes to safely - include headers like tree.h .

      -

      Second the two #defines allows to handle changes dones in the names of - public structures. Just make sure that you don't use the "root" name for - other structure in your module. Using xmlDocGetRootElement(doc) is the - proper way to access the root node now but is not available on old libxml - version (but present in 1.8.7).

      -
    4. -
    5. libxml-2 generates "empty" text nodes for "formatting spaces" found in - the XML input. The proper way to handle this change is to check them (and - ignore them) when scanning an XML tree produced after libxml parsing. The - quick and dirty solution is to force libxml to the old behaviour of - ignoring those formatting spaces by adding the following code before any - call to the XML parser: -
      #if defined(LIBXML_VERSION) && LIBXML_VERSION >= 20000
      -  xmlKeepBlanksDefault(0);
      -#endif
      -
    6. +
    7. similar include naming, one should use + #include<libxml/...> in both cases.
    8. +
    9. similar identifiers defined via macros for the child and root fields: + respectively xmlChildrenNode and + xmlRootNode
    10. +
    11. a new macro LIBXML_TEST_VERSION which should be + inserted once in the client code
    -

    Following those 3 steps should work. It worked for some of my own code and -for the gnome-print module. Other modules (including bonobo/gconf/nautilus) -will have to be patched in the same way.

    +

    So the roadmap to upgrade your existing libxml applications is the +following:

    +
      +
    1. install the libxml-1.8.8 (and libxml-devel-1.8.8) packages
    2. +
    3. find all occurences where the xmlDoc root field is used + and change it to xmlRootNode
    4. +
    5. similary find all occurences where the xmlNode childs + field is used and change it to xmlChildrenNode
    6. +
    7. add a LIBXML_TEST_VERSION macro somewhere in your + main() or in the library init entry point
    8. +
    9. Recompile, check compatibility, it should still work
    10. +
    11. install libxml2-2.1.0, remove libxml-devel-1.8.8 and install + libxml2-devel-2.1.0 (libxml-1.8.8 can be kept installed for legacy + stuff)
    12. +
    13. remove your config.cache, relaunch your configuration mechanism, and + recompile, if steps 2 and 3 were done right it should compile as-is
    14. +
    15. Test that your application is still running correctly, if not this may + be due to extra empty nodes due to formating spaces being kept in libxml2 + contrary to libxml1, in that case insert xmlKeepBlanksDefault(1) in your + code before calling the parser (next to + LIBXML_TEST_VERSION is a fine place).
    16. +
    + +

    Following those 3 steps should work. It worked for some of my own code.

    Let me put some emphasis on the fact that there is far more changes from libxml 1.x to 2.x than the ones you may have to patch for. The overall code @@ -142,6 +128,6 @@ upgrade, it may cost a lot on the long term ...

    Daniel Veillard

    -

    $Id: upgrade.html,v 1.4 2000/04/12 13:27:38 veillard Exp $

    +

    $Id: upgrade.html,v 1.5 2000/05/06 08:11:18 veillard Exp $

    diff --git a/example/gjobread.c b/example/gjobread.c index 916fa53a..cfd26d19 100644 --- a/example/gjobread.c +++ b/example/gjobread.c @@ -262,6 +262,7 @@ int main(int argc, char **argv) { gJobPtr cur; /* COMPAT: Do not genrate nodes for formatting spaces */ + LIBXML_TEST_VERSION xmlKeepBlanksDefault(0); for (i = 1; i < argc ; i++) {