使用TinyXML获取标签之间的内容

时间:2012-02-27 12:14:58

标签: c++ tinyxml xml

如何在标签之间获取内容

<name>  </name> and <mode> </mode>

<news>
    <name>Enter</name>
    <actions>
      <mode>me</mode>
    </actions>
   </news>

2 个答案:

答案 0 :(得分:5)

你应该真正了解TinyXML以及documentation的优秀the tutorial。但是,您要查找的是TiXmlElement的GetText()方法。

到达“名称”或“模式”元素后,您可以使用GetText()获取这些代码之间的字符串。

答案 1 :(得分:0)

\ this

TiXmlDocument doc("tes.xml");

   if (doc.LoadFile())
  {
     TiXmlHandle hDoc(&doc);
   TiXmlText* text = hDoc.ChildElement("news", 0).ChildElement("act-news", 0).ChildElement("name", 0).FirstChild().Text();
if(text)
{
const char* message = text->Value();
cout<<(message)<<endl; 
 } 

TiXmlText* stext = hDoc.ChildElement("news", 0).ChildElement("act-news", 1).ChildElement("name", 0).FirstChild().Text();
if(text)
{
const char* message = stext->Value();
cout<<(message)<<endl;