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
diff --git a/example/gjobread.c b/example/gjobread.c
index ce3f31b..ca38671 100644
--- a/example/gjobread.c
+++ b/example/gjobread.c
@@ -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 @@
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 @@
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 @@
}
}
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 @@
/*
* 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 @@
* 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 @@
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);
}