1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-12-29 11:21:26 +03:00

updated with instructions for support of both libxml-1.x and libxml-2.x

* doc/upgrade.html: updated with instructions for support of both
  libxml-1.x and libxml-2.x
* doc/gjobread.c : applied Todd Dukes <tdukes@ibmoto.com> patch
  for 2.x support and also fixed includes
Daniel
This commit is contained in:
Daniel Veillard 2000-05-06 08:11:19 +00:00
parent 496a1cf592
commit f302982d37
3 changed files with 94 additions and 16 deletions

View File

@ -1,3 +1,11 @@
Sat May 6 10:09:45 CEST 2000 Daniel Veillard <Daniel.Veillard@w3.org>
* doc/upgrade.html: updated with instructions for support of both
libxml-1.x and libxml-2.x
* doc/gjobread.c : applied Todd Dukes <tdukes@ibmoto.com> patch
for 2.x support and also fixed includes
Wed May 3 14:21:25 CEST 2000 Daniel Veillard <Daniel.Veillard@w3.org>
* encoding.[ch], xmlIO.[ch], parser.c, configure.in : revamped

View File

@ -3,13 +3,15 @@
<html>
<head>
<title>Upgrading libxml client code from 1.x to 2.x</title>
<meta name="GENERATOR" content="amaya V2.4">
<meta name="GENERATOR" content="amaya V3.1">
<meta http-equiv="Content-Type" content="text/html">
</head>
<body bgcolor="#ffffff">
<h1 align="center">Upgrading libxml client code from 1.x to 2.x</h1>
<h2>Incompatible changes:</h2>
<p>Version 2 of libxml is the first version introducing serious backward
incompatible changes. The main goals were:</p>
<ul>
@ -27,6 +29,8 @@ incompatible changes. The main goals were:</p>
before.</li>
</ul>
<h2>How to fix libxml-1.x code:</h2>
<p>So client code of libxml designed to run with version 1.x may have to be
changed to compile against version 2.x of libxml. Here is a list of changes
that I have collected, they may not be sufficient, so in case you find other
@ -83,18 +87,61 @@ mail</a>:</p>
<pre>xml-config --cflags</pre>
<p>output to generate you compile commands this will probably work out of
the box</p>
<p></p>
</li>
</ol>
<h2>Keeping 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>
<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>
</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>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 pacth for. The overall code
libxml 1.x to 2.x than the ones you may have to patch for. The overall code
has been considerably improved and the conformance to the XML specification
has been drastically improve. Don't take those changes as an excuse to not
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.3 2000/04/03 19:48:13 veillard Exp $</p>
<p>$Id: upgrade.html,v 1.4 2000/04/12 13:27:38 veillard Exp $</p>
</body>
</html>

View File

@ -10,7 +10,12 @@
#include <string.h>
#include <stdlib.h>
#include "parser.h"
#include <xmlmemory.h>
#if defined(LIBXML_VERSION) && LIBXML_VERSION >= 20000
#include <libxml/parser.h>
#else
#include <gnome-xml/parser.h>
#endif
#define DEBUG(x) printf(x)
@ -45,12 +50,12 @@ DEBUG("parsePerson\n");
memset(ret, 0, sizeof(person));
/* We don't care what the top level element name is */
cur = cur->childs;
cur = cur->children;
while (cur != NULL) {
if ((!strcmp(cur->name, "Person")) && (cur->ns == ns))
ret->name = xmlNodeListGetString(doc, cur->childs, 1);
ret->name = xmlNodeListGetString(doc, cur->children, 1);
if ((!strcmp(cur->name, "Email")) && (cur->ns == ns))
ret->email = xmlNodeListGetString(doc, cur->childs, 1);
ret->email = xmlNodeListGetString(doc, cur->children, 1);
cur = cur->next;
}
@ -103,7 +108,7 @@ DEBUG("parseJob\n");
memset(ret, 0, sizeof(job));
/* We don't care what the top level element name is */
cur = cur->childs;
cur = cur->children;
while (cur != NULL) {
if ((!strcmp(cur->name, "Project")) && (cur->ns == ns)) {
@ -113,9 +118,9 @@ DEBUG("parseJob\n");
}
}
if ((!strcmp(cur->name, "Application")) && (cur->ns == ns))
ret->application = xmlNodeListGetString(doc, cur->childs, 1);
ret->application = xmlNodeListGetString(doc, cur->children, 1);
if ((!strcmp(cur->name, "Category")) && (cur->ns == ns))
ret->category = xmlNodeListGetString(doc, cur->childs, 1);
ret->category = xmlNodeListGetString(doc, cur->children, 1);
if ((!strcmp(cur->name, "Contact")) && (cur->ns == ns))
ret->contact = parsePerson(doc, ns, cur);
cur = cur->next;
@ -167,7 +172,10 @@ gJobPtr parseGjobFile(char *filename) {
/*
* Check the document is of the right kind
*/
cur = doc->root;
// cur = doc->root;
// cur = doc->children;
cur = xmlDocGetRootElement(doc);
if (cur == NULL) {
fprintf(stderr,"empty document\n");
xmlFreeDoc(doc);
@ -201,16 +209,27 @@ gJobPtr parseGjobFile(char *filename) {
* Now, walk the tree.
*/
/* First level we expect just Jobs */
cur = cur->childs;
// cur = cur->children;
cur = cur -> children;
while ( cur && xmlIsBlankNode ( cur ) )
{
cur = cur -> next;
}
if ( cur == 0 )
return ( NULL );
if ((strcmp(cur->name, "Jobs")) || (cur->ns != ns)) {
fprintf(stderr,"document of the wrong type, Jobs expected");
fprintf(stderr,"document of the wrong type, was '%s', Jobs expected",
cur->name);
fprintf(stderr,"xmlDocDump follows\n");
xmlDocDump ( stderr, doc );
fprintf(stderr,"xmlDocDump finished\n");
xmlFreeDoc(doc);
free(ret);
return(NULL);
}
/* Second level is a list of Job, but be laxist */
cur = cur->childs;
cur = cur->children;
while (cur != NULL) {
if ((!strcmp(cur->name, "Job")) && (cur->ns == ns)) {
job = parseJob(doc, ns, cur);
@ -240,7 +259,11 @@ int main(int argc, char **argv) {
for (i = 1; i < argc ; i++) {
cur = parseGjobFile(argv[i]);
handleGjob(cur);
if ( cur )
handleGjob(cur);
else
fprintf( stderr, "Error parsing file '%s'\n", argv[i]);
}
return(0);
}