Есть .xml файлик: | Код | <?xml version="1.0"?> <Bible> <XMLBIBLE biblename="Russian"> <BIBLEBOOK bname="Genesis"> <CHAPTER cnumber="1"> <VERS vnumber="1">In the beginning God created the heavens and the earth.</VERS> </CHAPTER> </BIBLEBOOK> </XMLBIBLE> </Bible>
|
Не могу получить аттрибуты тега "BIBLEBOOK", зато аттрибуты "XMLBIBLE" считываются. | Код | QMap<QString, QString> Bible::parseBook(QXmlStreamReader& xml) { QMap<QString, QString> xmlbible; QXmlStreamAttributes attributes = xml.attributes();
if(xml.tokenType() != QXmlStreamReader::StartElement && xml.name() == "XMLBIBLE") { return xmlbible; } if(attributes.hasAttribute("biblename")) { xmlbible["biblename"] = attributes.value("biblename").toString(); }
if(xml.tokenType() == QXmlStreamReader::StartElement && xml.name() == "BIBLEBOOK") { if(attributes.hasAttribute("bname")) { xmlbible["bname"] = attributes.value("bname").toString(); } } xml.readNext();
while(!(xml.tokenType() == QXmlStreamReader::EndElement && xml.name() == "Bible")) { if(xml.tokenType() == QXmlStreamReader::StartElement) { /*название книги*/ if(xml.name() == "BIBLEBOOK") { this->addElementDataToMap(xml, xmlbible); } /*номер главы*/ if(xml.name() == "CHAPTER") { this->addElementDataToMap(xml, xmlbible); } /*номер текста*/ if(xml.name() == "VERS") { this->addElementDataToMap(xml, xmlbible); } } xml.readNext(); } return xmlbible; }
|
|