2011-12-23 10 views
1

javascriptで、私は "PLOT"としてすべてのタグ名を見つけて、それぞれのタグ名の属性値とノード値を取得したいと思っています。私は次の関数を使うことができます。は、javascriptのreal xml関数と同等ですか?

<PLOT attr="1">a</PLOT> 
<PLOT attr="2">b</PLOT> 
<PLOT attr="3">c</PLOT> 
<PLOT attr="4">d</PLOT> 


xmlhttp.open("GET","xmltag.xml",false); 
x2=xmlDoc.getElementsByTagName("PLOT"); 

for (i=0;i<x2.length;i++) 
    { 
attribute=x2[i].getAttribute("attr"); 
value=x2[i].childNodes[0].nodeValue; 
    } 

であり、1a 2b 3c 4dが得られる。

私はQtの、

QDomDocument doc2("MyML"); 
QFile file("../xmltag.xml"); 
file.close(); 

と何が次のステップであるべきでC/C++から同じことをやろうとしていますか?

おかげ

答えて

3

QDomDocumentQDomElementのドキュメントを見てください。基本的にはJavaScriptとそれほど違いはありません:

QDomNodeList nodes = doc.elementsByTagName("PLOT"); 
for (int i = 0; i < nodes.size(); i++) { 
    QDomElement element = nodes.at(i).toElement(); 
    qDebug() << element.text(); // Get the content of the element 
} 
関連する問題