View Issue Details

IDProjectCategoryView StatusLast Update
0000136easycwmpEnhancementpublic2016-05-26 10:11
Reportermohamed.kallel Assigned Tomohamed.kallel  
PrioritynormalSeverityminorReproducibilityhave not tried
Status resolvedResolutionno change required 
Summary0000136: use mxmlGetNextSibling() in xml_get_value_with_whitespace()
DescriptionAccording to an EasyCwmp contributor, it's better to use mxmlGetNextSibling() in
xml_get_value_with_whitespace() in this way:

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;
}

attached test.c and test.xml
TagsNo tags attached.
e-mail notification

Activities

mohamed.kallel

2016-05-17 16:32

administrator  

test.c (1,182 bytes)   
#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);
}

test.c (1,182 bytes)   

mohamed.kallel

2016-05-17 16:32

administrator  

test.xml (79 bytes)   
<a>
<b>
<ParameterName>this is something with spaces</ParameterName>
</b>
</a>
test.xml (79 bytes)   

mohamed.kallel

2016-05-26 10:11

administrator   ~0000478

this issue is uselss since the use of mxmlGetNextSibling() could cause many cases to take in account. So we keep the current solution for the moment

Issue History

Date Modified Username Field Change
2016-05-17 16:31 mohamed.kallel New Issue
2016-05-17 16:32 mohamed.kallel File Added: test.c
2016-05-17 16:32 mohamed.kallel File Added: test.xml
2016-05-26 10:11 mohamed.kallel Note Added: 0000478
2016-05-26 10:11 mohamed.kallel Status new => resolved
2016-05-26 10:11 mohamed.kallel Resolution open => no change required
2016-05-26 10:11 mohamed.kallel Assigned To => mohamed.kallel