c programming with xml

Hi all,
I am suppose to write a program that will take in a xml file and display the value of each attribute that is in the xml file. i have some code but i didn't know where should some of the file be written.

Can some one help me?

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <libxml/xmlmemory.h>
//#include <libxml/parser.h>

// #include "parsedoc.h"

void
getReference (xmlDocPtr doc, xmlNodePtr cur) {

  xmlChar *uri;
  cur = cur->xmlChildrenNode;
  while (cur != NULL) {
    if ((!xmlStrcmp(cur->name, (const xmlChar *)"reference"))) {
      uri = xmlGetProp(cur, "uri");
      printf("uri: %s\n", uri);
      xmlFree(uri);
    }
    cur = cur->next;
  }
  return;
}


int
main(int argc, char **argv) {

  char *docname;
  xmlDocPtr doc;

  if (argc <= 1) {
    printf("Usage: %s docname\n", argv[0]);
    return(0);
  }

  docname = argv[1];
  doc = parseDoc (docname);
  if ( doc != NULL ) {
    xmlNodePtr cur;
    cur = xmlDocGetRootElement(doc);
    getReference (doc, cur);
    xmlFreeDoc(doc);
  }

  return (1);
}

I didn't know how to continue from here.
Give me some ideas or clue if possible.
Or you can msn me dianazheng@hotmail.com.

Seems this code is using libxml2 tool. So you need to download and install libxml2 into your OS, then compile your code.

Normally there will be some problem when you install libxml2. But hopefully you could get lucky.

Do you have any examples that is close to what i am trying to do now, or would you mind giving me some examples.

Thanks in advance..

I need HELP!!!!

When i run my C programe with a makefile that i have created, it give me this error message, can anyone tell me what is the meaning of
undefined reference to `xmlStrcmp'

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>

// search for and print out text associated with "keyword" tag
void
//parseStory (xmlDocPtr doc, xmlNodePtr cur) {
parseFile (xmlDocPtr doc, xmlNodePtr cur) {

  xmlChar *key;
 
  // look for "keyword" tag among storyinfo's children
  cur = cur->xmlChildrenNode;
  while (cur != NULL) {
    
    if ((!xmlStrcmp(cur->name, (const xmlChar *) "name"))) {
      key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
      printf("Name: %s\n", key);
      //printf("keyword: %s\n", key);
      xmlFree(key);
    }
    
    if ((!xmlStrcmp(cur->name, (const xmlChar *) "description"))) {
      key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
      printf("Description: %s\n", key);
      //printf("keyword: %s\n", key);
      xmlFree(key);
    }
    
    if ((!xmlStrcmp(cur->name, (const xmlChar *) "exits"))) {
      key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
      printf("Exits: %s\n", key);
      //printf("keyword: %s\n", key);
      xmlFree(key);
    }
    cur = cur->next;
  }
  return;
}

static void
parseDoc(char *docname) {

  xmlDocPtr doc;
  xmlNodePtr cur;
  //char *cur;           //add

  doc = xmlParseFile(docname);

  if (doc == NULL) {
    fprintf(stderr,"Document not parsed successfully. \n");
    return;
  }

  cur = xmlDocGetRootElement(doc);

  if (cur == NULL) {
    fprintf(stderr,"Document is empty. \n");
    xmlFreeDoc(doc);
    return;
  }

  // root tag must be "story"
  if (!xmlStrcmp(cur->name, (const xmlChar *) "gameworld")) {
    fprintf(stderr,"Document of the wrong type, root node != gameworld");
    xmlFreeDoc(doc);
    return;
  }
}

int
main(int argc, char **argv) {

  char *docname;

  if (argc <= 1) {
    printf("Usage: %s docname\n", argv[0]);
    return(0);
  }

  docname = argv[1];
  parseDoc (docname);

  return (1);
}

The error message

$ make task2a
cc `xml2-config --cflags` -c task2a.c
cc task2a.o -o readworld1 `xml2-config --libs`
cc   task2a.o readworld1   -o task2a
collect2: ld terminated with signal 11 [Segmentation fault]
readworld1(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc-lib/i486-linux/3.3.4/../../../crt1.o(.rodata+0x0):../sysdeps/i386/elf/start.S:47: first defined here
readworld1(.data+0x4): In function `__data_start':
: multiple definition of `__dso_handle'
/usr/lib/gcc-lib/i486-linux/3.3.4/crtbegin.o(.data+0x0): first defined here
readworld1(.init+0x0): In function `_init':
/disk/hdc2/glibc/debian-build/glibc_2.3.2.ds1-13.test3/glibc-2.3.2.ds1/build-tree/i386-libc/csu/crti.S:35: multiple definition of `_init'
/usr/lib/gcc-lib/i486-linux/3.3.4/../../../crti.o(.init+0x0):/disk/hdc2/glibc/debian-build/glibc_2.3.2.ds1-13.test3/glibc-2.3.2.ds1/build-tree/i386-libc/csu/crti.S:12: first defined here
readworld1(.text+0x0): In function `_start':
../sysdeps/i386/elf/start.S:47: multiple definition of `_start'
/usr/lib/gcc-lib/i486-linux/3.3.4/../../../crt1.o(.text+0x0):../sysdeps/i386/elf/start.S:47: first defined here
readworld1(.text+0x29f): In function `main':
: multiple definition of `main'
task2a.o(.text+0x1db): first defined here
readworld1(.fini+0x0): In function `_fini':
/disk/hdc2/glibc/debian-build/glibc_2.3.2.ds1-13.test3/glibc-2.3.2.ds1/build-tree/i386-libc/csu/crti.S:51: multiple definition of `_fini'
/usr/lib/gcc-lib/i486-linux/3.3.4/../../../crti.o(.fini+0x0): first defined here
readworld1(*ABS*+0x8049bf4): In function `__init_array_start':
task2a.c: multiple definition of `_GLOBAL_OFFSET_TABLE_'
/usr/lib/gcc-lib/i486-linux/3.3.4/../../../crt1.o(.got.plt+0x0):../sysdeps/i386/elf/start.S:47: first defined here
readworld1(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc-lib/i486-linux/3.3.4/../../../crt1.o(.rodata+0x4):../sysdeps/i386/elf/start.S:53: first defined here
readworld1(.data+0x0): In function `__data_start':
: multiple definition of `__data_start'
/usr/lib/gcc-lib/i486-linux/3.3.4/../../../crt1.o(.data+0x0):../sysdeps/i386/elf/start.S:47: first defined here
readworld1(.text+0xc4): In function `parseFile':
: multiple definition of `parseFile'
task2a.o(.text+0x0): first defined here
/usr/lib/gcc-lib/i486-linux/3.3.4/../../../crt1.o(.dynamic+0x0):../sysdeps/i386/elf/start.S:47: multiple definition of `_DYNAMIC'
task2a.o(.text+0x2c): In function `parseFile':
: undefined reference to `xmlStrcmp'
task2a.o(.text+0x4d): In function `parseFile':
: undefined reference to `xmlNodeListGetString'
task2a.o(.text+0x86): In function `parseFile':
: undefined reference to `xmlStrcmp'
task2a.o(.text+0xa7): In function `parseFile':
: undefined reference to `xmlNodeListGetString'
task2a.o(.text+0xe0): In function `parseFile':
: undefined reference to `xmlStrcmp'
task2a.o(.text+0x101): In function `parseFile':
: undefined reference to `xmlNodeListGetString'
task2a.o(.text+0x145): In function `parseDoc':
: undefined reference to `xmlParseFile'
task2a.o(.text+0x170): In function `parseDoc':
: undefined reference to `xmlDocGetRootElement'
task2a.o(.text+0x199): In function `parseDoc':
: undefined reference to `xmlFreeDoc'
task2a.o(.text+0x1b1): In function `parseDoc':
: undefined reference to `xmlStrcmp'
task2a.o(.text+0x1d5): In function `parseDoc':
: undefined reference to `xmlFreeDoc'
make: *** [task2a] Error 1