diff --git a/utils/xmlgrep/printtree.c b/utils/xmlgrep/printtree.c index 674a7d14a..e4e8c490b 100644 --- a/utils/xmlgrep/printtree.c +++ b/utils/xmlgrep/printtree.c @@ -4,7 +4,7 @@ #include "xml.h" -void print_xml(void *, char *, int); +void print_xml(void *, char *, unsigned int); int main(int argc, char **argv) { @@ -47,7 +47,7 @@ int main(int argc, char **argv) } } -void print_xml(void *id, char *name, int len) +void print_xml(void *id, char *name, unsigned int len) { void *xid = xmlMarkId(id); unsigned int i, num; @@ -72,8 +72,21 @@ void print_xml(void *id, char *name, int len) { if (xmlNodeGetPos(id, xid, "*", i) != 0) { - int res, i = 4096 - len; + unsigned int res, i = 4096 - len; res = xmlNodeCopyName(xid, (char *)&name[len], i); + if (res) + { + unsigned int index = xmlAttributeGetInt(xid, "n"); + if (index) + { + unsigned int pos = len+res; + + name[pos++] = '['; + i = snprintf((char *)&name[pos], 4096-pos, "%i", index); + name[pos+i] = ']'; + res += i+2; + } + } print_xml(xid, name, len+res); } else printf("error\n"); diff --git a/utils/xmlgrep/xml.c b/utils/xmlgrep/xml.c index 8faa1f962..5357ed81a 100644 --- a/utils/xmlgrep/xml.c +++ b/utils/xmlgrep/xml.c @@ -465,10 +465,11 @@ xmlGetString(const void *id) char *ps; ps = xid->start; - len = xid->len; + len = xid->len-1; __xmlPrepareData(&ps, &len); if (len) { + len++; str = malloc(len+1); if (str) {