#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <pthread.h>
#include <microxml.h>

/*  gcc -g -o test test.c -lmicroxml -lpthread
 */

char *xml_get_value_with_whitespace(mxml_node_t **b)
{
    //b is a TEXT and it is the first child in the ELEMENT
    //If a string has spaces, it is represented as multiple TEXT siblings.

    char * value = calloc(1, sizeof(char));
    do {
        value = realloc(value, strlen(value) + strlen((*b)->value.text.string) + 2);
 
        /*handle leading space before this string*/
        if ((*b)->value.text.whitespace == 1)  
            strcat(value, " ");

        strcat(value, (*b)->value.text.string);

     } while ((*b = mxmlGetNextSibling(*b)) &&   
                   (*b)->type == MXML_TEXT);
  return value;
}

void main (void)
{
  FILE* fp;
  mxml_node_t* b;
  char *value;

  fp = fopen("test.xml", "r");
  b = mxmlLoadFile(NULL, fp, MXML_TEXT_CALLBACK);
  fclose(fp);

  //I want to get the string content
  b  = mxmlFindElement(b, b, "ParameterName", NULL, NULL, MXML_DESCEND);

  b = mxmlGetFirstChild(b);
  value = xml_get_value_with_whitespace(&b);
  printf("value is --%s--\n", value);
  free(value);
}

