【发布时间】:2014-03-18 09:50:33
【问题描述】:
为什么这段代码只检索标签,而不检索值?
int fromString(char* str)
{
mxml_node_t *root, *node;
root = mxmlLoadString(NULL,str, MXML_TEXT_CALLBACK);
node = root;
const char *textValue;
char bbb [256];
const char *name;
int aaa;
mxmlGetElement(node);
if (!strcmp(mxmlGetElement(node),"Root" ))
{
node = mxmlGetFirstChild(node);
while (name= mxmlGetElement(node))
{
if (!strcmp(name,"AAA" ))
{
cout<<"getting AAA"<<endl;
aaa= mxmlGetInteger(node);
cout<<aaa<<std::endl;
} else
if (!strcmp(name,"BBB" ))
{
cout<<"getting BBB"<<endl;
textValue=mxmlGetText(node,0);
if (textValue!=NULL)
{
strcpy(bbb,textValue);
cout<<textValue<<std::endl;
}
}
node = mxmlGetNextSibling(node);
}
return 0;
} else return -1;
}
int _tmain(int argc, _TCHAR* argv[])
{
fromString("<Root><AAA>12</AAA><BBB>txt</BBB></Root>");
int i ;
cin>>i;
}
输出:
getting AAA
0
getting BBB
【问题讨论】:
标签: c++ xml xml-parsing