aboutsummaryrefslogtreecommitdiffstats
path: root/example
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2000-05-06 08:11:19 +0000
committerDaniel Veillard <veillard@src.gnome.org>2000-05-06 08:11:19 +0000
commitf302982d37171c71358523255b79ad806f0ea6ce (patch)
treea0f85b09edc7603486b76e7893adc56514f4ae18 /example
parent496a1cf59284292275cc5643e6078748dc79340e (diff)
downloadandroid_external_libxml2-f302982d37171c71358523255b79ad806f0ea6ce.tar.gz
android_external_libxml2-f302982d37171c71358523255b79ad806f0ea6ce.tar.bz2
android_external_libxml2-f302982d37171c71358523255b79ad806f0ea6ce.zip
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
Diffstat (limited to 'example')
-rw-r--r--example/gjobread.c47
1 files changed, 35 insertions, 12 deletions
diff --git a/example/gjobread.c b/example/gjobread.c
index ce3f31bb..ca386718 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 @@ 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);
}