开发者

how to obtain the value from an xml tag using FirstCHildElement

I am working in C++. I would like to ask how to obtain the value text from:

<message> text </message>

I have

TiXmlHandle handle(&doc);
TiXmlElement* section;
section=doc.FirstChildElement("message");

How to do it from now on? I know I have to work with .Eleme开发者_StackOverflow社区nt() but I don't know how.


You can use the function GetText() to obtain the contents of <message>. I put your XML-contents in a file called dummy.xml and used the following code to print the contents:

TiXmlDocument doc("dummy.xml");

if(doc.LoadFile())
{
    TiXmlHandle hDoc(&doc);
    TiXmlElement *pRoot;
    pRoot = doc.FirstChildElement("message");
    printf("pRoot text: %s", pRoot->GetText());

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜