2012-02-27 64 views
1

標籤之間的內容我怎樣才能標籤獲取使用TinyXML的

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

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

你嘗試過什麼代碼,它是否有什麼問題,你覺得什麼工作? – ssube 2012-02-27 12:16:58

+0

我解決了這個帖子的幫助 – Max 2012-02-27 13:57:11

回答

4

之間的內容你真的應該看看的TinyXML的優秀documentation以及the tutorial。但是,您正在尋找的是TiXmlElement的GetText()方法。

一旦你到達你的「名稱」或「模式」元素,你可以得到這些標籤之間的字符串與GetText()

+0

有用,謝謝! – Max 2012-02-27 12:33:17

0

\這個

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;