Fix a bug in xmlGetString and honour the index attribtute 'n'
This commit is contained in:
parent
783fa8dd7d
commit
84221ac794
2 changed files with 18 additions and 4 deletions
|
@ -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");
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue