如何使用FirstCHildElement从xml标记获取值 [英] how to obtain the value from an xml tag using FirstCHildElement
本文介绍了如何使用FirstCHildElement从xml标记获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用C ++.我想问一下如何从以下位置获取值文本:
I am working in C++. I would like to ask how to obtain the value text from:
<message> text </message>
我有
TiXmlHandle handle(&doc);
TiXmlElement* section;
section=doc.FirstChildElement("message");
从现在开始该怎么做?我知道我必须使用.Element()
,但是我不知道如何.
How to do it from now on? I know I have to work with .Element()
but I don't know how.
推荐答案
您可以使用函数GetText()
获取<message>
的内容.我将您的XML内容放入名为dummy.xml
的文件中,并使用以下代码来打印内容:
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());
}
这篇关于如何使用FirstCHildElement从xml标记获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文