2.1.0 test release for good, updated doc and example, Daniel.

This commit is contained in:
Daniel Veillard 2000-06-29 00:43:27 +00:00
parent be803967db
commit c230410ead
2 changed files with 39 additions and 52 deletions

View File

@ -3,7 +3,7 @@
<html>
<head>
<title>Upgrading libxml client code from 1.x to 2.x</title>
<meta name="GENERATOR" content="amaya V3.1">
<meta name="GENERATOR" content="amaya V2.1">
<meta http-equiv="Content-Type" content="text/html">
</head>
@ -48,17 +48,7 @@ mail</a>:</p>
Use <strong>xmlDocGetRootElement(doc)</strong> 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.
<p><strong>Note</strong>: 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):</p>
<pre>#if defined(LIBXML_VERSION) &amp;&amp; LIBXML_VERSION >= 20000
#define root children
#define childs children
#endif
</pre>
</li>
will probably do it. </li>
<li>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</a>:</p>
</li>
</ol>
<h2>Keeping both libxml-1.x and libxml-2.x compatibility:</h2>
<h2>Ensuring both libxml-1.x and libxml-2.x compatibility</h2>
<p>Here is the steps i applied successfully to a couple of gnome project
dependant on libxml to allow compilation under both environments:</p>
<p>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:</p>
<ol>
<li>make sure your configure adds the output of "xml-config --cflags" to
the compiler command line</li>
<li>in your C files including libxml includes do the following
<pre>#include &lt;xmlmemory.h>
#if defined(LIBXML_VERSION) &amp;&amp; LIBXML_VERSION >= 20000
#include &lt;libxml/parser.h>
#include &lt;libxml/tree.h>
#define root children
#define childs children
#else
#include &lt;gnome-xml/parser.h>
#include &lt;gnome-xml/tree.h>
#endif</pre>
<p>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 .</p>
<p>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).</p>
</li>
<li>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:
<pre>#if defined(LIBXML_VERSION) &amp;&amp; LIBXML_VERSION >= 20000
xmlKeepBlanksDefault(0);
#endif</pre>
</li>
<li>similar include naming, one should use
<strong>#include&lt;libxml/...></strong> in both cases.</li>
<li>similar identifiers defined via macros for the child and root fields:
respectively <strong>xmlChildrenNode</strong> and
<strong>xmlRootNode</strong> </li>
<li>a new macro <strong>LIBXML_TEST_VERSION</strong> which should be
inserted once in the client code</li>
</ol>
<p>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. </p>
<p>So the roadmap to upgrade your existing libxml applications is the
following:</p>
<ol>
<li>install the libxml-1.8.8 (and libxml-devel-1.8.8) packages</li>
<li>find all occurences where the xmlDoc <strong>root</strong> field is used
and change it to <strong>xmlRootNode</strong></li>
<li>similary find all occurences where the xmlNode <strong>childs</strong>
field is used and change it to <strong>xmlChildrenNode</strong></li>
<li>add a <strong>LIBXML_TEST_VERSION</strong> macro somewhere in your
<strong>main()</strong> or in the library init entry point</li>
<li>Recompile, check compatibility, it should still work</li>
<li>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)</li>
<li>remove your config.cache, relaunch your configuration mechanism, and
recompile, if steps 2 and 3 were done right it should compile as-is</li>
<li>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
<strong>LIBXML_TEST_VERSION</strong> is a fine place).</li>
</ol>
<p>Following those 3 steps should work. It worked for some of my own code.</p>
<p>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 ...</p>
<p><a href="mailto:Daniel.Veillard@w3.org">Daniel Veillard</a></p>
<p>$Id: upgrade.html,v 1.4 2000/04/12 13:27:38 veillard Exp $</p>
<p>$Id: upgrade.html,v 1.5 2000/05/06 08:11:18 veillard Exp $</p>
</body>
</html>

View File

@ -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++) {