1
解析當我們嘗試分析與QT的XML文檔中,我們使用類似:XML與QT
QString str;
QXmlStreamAttributes attrib = xml_reader.attributes();
if(attrib.hasAttribute("id"))
{
str = attrib.value("id").toString();
}
要做到這一點,我需要知道的屬性稱爲「ID」。有沒有辦法在不知道名稱的情況下閱讀第一個屬性?
在此先感謝。
當你說「第一個屬性」你是什麼意思?屬性的順序沒有在XML中定義。因此,您必須確定使用特定條件的「第一個」 – AnatolyS
QXmlStreamAttributes是一個向量。你應該能夠直接索引「第一個」QXMLStreamAttribute。 XML再次沒有指定屬性的順序。 – Ajith