问题
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