how to obtain the value from an xml tag using FirstCHildElement

╄→尐↘猪︶ㄣ 提交于 2019-12-11 07:50:08

问题


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 .Element() but I don't know how.


回答1:


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());

}


来源:https://stackoverflow.com/questions/6531694/how-to-obtain-the-value-from-an-xml-tag-using-firstchildelement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!