diff --git a/xmlparser.cpp b/xmlparser.cpp new file mode 100644 index 0000000000000000000000000000000000000000..717b1b207844f78c2f0703c4b776cbb6d467650d --- /dev/null +++ b/xmlparser.cpp @@ -0,0 +1,45 @@ +#include "xmlparser.h" +#include "ui_mainwindow.h" + +bool XMLParser::startElement(const QString&, + const QString&, + const QString& tagName, + const QXmlAttributes& + ) +{ + if(tagName == "catalog") + treeItem = new QTreeWidgetItem(treeWidget); + + else + treeItem = new QTreeWidgetItem(treeItem); + return true; +} + +// ------------------------------------------------------------------ +bool XMLParser::characters(const QString& strText) +{ + m_strText = ": " + strText; + return true; +} + +// ------------------------------------------------------------------ +bool XMLParser::endElement(const QString&, const QString&, const QString& str) +{ + treeItem->setText(0, str + m_strText); + if(treeItem->parent() && treeItem->parent()->text(0) == "") + treeItem = treeItem->parent(); + m_strText = ""; + if(str == "catalog") + treeItem->setText(0, title); + +return true; +} + +// ------------------------------------------------------------------ +bool XMLParser::fatalError(const QXmlParseException& exception) +{ + QString str = "Line: " + QString::number(exception.lineNumber()) + ", Column: " + QString::number(exception.columnNumber()) + ", Message: " + exception.message(); + QMessageBox::warning(nullptr, "Ошибка", str); + + return false; +}