* xode_insert_cdata -- append character data to a tag * If last child of the parent is CDATA, merges CDATA nodes. Otherwise * creates a CDATA node, and appends it to the parent's child list. * * parameters * parent -- parent tag * CDATA -- character data * size -- size of CDATA * or -1 for null-terminated CDATA strings * * returns * a pointer to the
| 288 | * or NULL if it was unsuccessful |
| 289 | */ |
| 290 | xode xode_insert_cdata(xode parent, const char* CDATA, unsigned int size) |
| 291 | { |
| 292 | xode result; |
| 293 | |
| 294 | if(CDATA == NULL || parent == NULL) |
| 295 | return NULL; |
| 296 | |
| 297 | if(size == -1) |
| 298 | size = strlen(CDATA); |
| 299 | |
| 300 | if ((parent->lastchild != NULL) && (parent->lastchild->type == XODE_TYPE_CDATA)) |
| 301 | { |
| 302 | result = parent->lastchild; |
| 303 | result->data = _xode_merge(result->p, result->data, result->data_sz, CDATA, size); |
| 304 | result->data_sz = result->data_sz + size; |
| 305 | } |
| 306 | else |
| 307 | { |
| 308 | result = _xode_insert(parent, "", XODE_TYPE_CDATA); |
| 309 | if (result != NULL) |
| 310 | { |
| 311 | result->data = (char*)xode_pool_malloc(result->p, size + 1); |
| 312 | memcpy(result->data, CDATA, size); |
| 313 | result->data[size] = '\0'; |
| 314 | result->data_sz = size; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | return result; |
| 319 | } |
| 320 | |
| 321 | |
| 322 | /* |
no test coverage detected