mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-08-05 19:35:54 +03:00
2.1.0 test release for good, updated doc and example, Daniel.
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Upgrading libxml client code from 1.x to 2.x</title>
|
<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">
|
<meta http-equiv="Content-Type" content="text/html">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
@@ -48,17 +48,7 @@ mail</a>:</p>
|
|||||||
Use <strong>xmlDocGetRootElement(doc)</strong> to get the root element of
|
Use <strong>xmlDocGetRootElement(doc)</strong> to get the root element of
|
||||||
a document. Alternatively if you are sure to not reference Dtds nor have
|
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
|
PIs or comments before or after the root element s/->root/->children/g
|
||||||
will probably do it.
|
will probably do it. </li>
|
||||||
<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) && LIBXML_VERSION >= 20000
|
|
||||||
#define root children
|
|
||||||
#define childs children
|
|
||||||
#endif
|
|
||||||
</pre>
|
|
||||||
</li>
|
|
||||||
<li>The white space issue, this one is more complex, unless special case of
|
<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
|
validating parsing, the line breaks and spaces usually used for indenting
|
||||||
and formatting the document content becomes significant. So they are
|
and formatting the document content becomes significant. So they are
|
||||||
@@ -90,49 +80,45 @@ mail</a>:</p>
|
|||||||
</li>
|
</li>
|
||||||
</ol>
|
</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
|
<p>Two new version of libxml (1.8.8) and libxml2 (2.1.0) have been released to
|
||||||
dependant on libxml to allow compilation under both environments:</p>
|
allow smoth upgrade of existing libxml v1code while retaining compatibility.
|
||||||
|
They offers the following:</p>
|
||||||
<ol>
|
<ol>
|
||||||
<li>make sure your configure adds the output of "xml-config --cflags" to
|
<li>similar include naming, one should use
|
||||||
the compiler command line</li>
|
<strong>#include<libxml/...></strong> in both cases.</li>
|
||||||
<li>in your C files including libxml includes do the following
|
<li>similar identifiers defined via macros for the child and root fields:
|
||||||
<pre>#include <xmlmemory.h>
|
respectively <strong>xmlChildrenNode</strong> and
|
||||||
#if defined(LIBXML_VERSION) && LIBXML_VERSION >= 20000
|
<strong>xmlRootNode</strong> </li>
|
||||||
#include <libxml/parser.h>
|
<li>a new macro <strong>LIBXML_TEST_VERSION</strong> which should be
|
||||||
#include <libxml/tree.h>
|
inserted once in the client code</li>
|
||||||
#define root children
|
|
||||||
#define childs children
|
|
||||||
#else
|
|
||||||
#include <gnome-xml/parser.h>
|
|
||||||
#include <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) && LIBXML_VERSION >= 20000
|
|
||||||
xmlKeepBlanksDefault(0);
|
|
||||||
#endif</pre>
|
|
||||||
</li>
|
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
<p>Following those 3 steps should work. It worked for some of my own code and
|
<p>So the roadmap to upgrade your existing libxml applications is the
|
||||||
for the gnome-print module. Other modules (including bonobo/gconf/nautilus)
|
following:</p>
|
||||||
will have to be patched in the same way. </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
|
<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
|
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><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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@@ -262,6 +262,7 @@ int main(int argc, char **argv) {
|
|||||||
gJobPtr cur;
|
gJobPtr cur;
|
||||||
|
|
||||||
/* COMPAT: Do not genrate nodes for formatting spaces */
|
/* COMPAT: Do not genrate nodes for formatting spaces */
|
||||||
|
LIBXML_TEST_VERSION
|
||||||
xmlKeepBlanksDefault(0);
|
xmlKeepBlanksDefault(0);
|
||||||
|
|
||||||
for (i = 1; i < argc ; i++) {
|
for (i = 1; i < argc ; i++) {
|
||||||
|
Reference in New Issue
Block a user