74 |
|
return xml; |
75 |
|
} |
76 |
|
|
77 |
+ |
/* returns the given tag's character content or empty string if none */ |
78 |
+ |
char *ezxml_txt(ezxml_t xml) |
79 |
+ |
{ |
80 |
+ |
if (xml == NULL) |
81 |
+ |
return ""; |
82 |
+ |
return xml->txt; |
83 |
+ |
} |
84 |
+ |
|
85 |
|
/* returns the Nth tag with the same name in the same subsection or NULL if not */ |
86 |
|
/* found */ |
87 |
|
ezxml_t ezxml_idx(ezxml_t xml, int idx) |
930 |
|
ezxml_t ezxml_set_txt(ezxml_t xml, const char *txt) |
931 |
|
{ |
932 |
|
if (! xml) return NULL; |
933 |
+ |
if (txt == xml->txt) return xml; |
934 |
|
if (xml->flags & EZXML_TXTM) free(xml->txt); /* existing txt was malloced */ |
935 |
|
xml->flags &= ~EZXML_TXTM; |
936 |
|
xml->txt = (char *)txt; |
937 |
|
return xml; |
938 |
+ |
} |
939 |
+ |
|
940 |
+ |
/* add text to the current character content, allocating memory as needed (GW) */ |
941 |
+ |
ezxml_t ezxml_add_txt(ezxml_t xml, const char *txt) |
942 |
+ |
{ |
943 |
+ |
int len; |
944 |
+ |
if (! xml) return NULL; |
945 |
+ |
if (!*txt) return xml; |
946 |
+ |
len = strlen(xml->txt) + strlen(txt) + 1; |
947 |
+ |
if (xml->flags & EZXML_TXTM) { |
948 |
+ |
xml->txt = (char *)realloc(xml->txt, len); |
949 |
+ |
} else { |
950 |
+ |
xml->txt = strcpy((char *)malloc(len), xml->txt); |
951 |
+ |
xml->flags |= EZXML_TXTM; |
952 |
+ |
} |
953 |
+ |
strcat(xml->txt, txt); |
954 |
+ |
return xml; |
955 |
|
} |
956 |
|
|
957 |
|
/* Sets the given tag attribute or adds a new attribute if not found. A value */ |