49 if (!QFile::exists(File))
51 m_message = QStringLiteral(
"File '%1' does not exist").arg(File);
56 if (!file.open(QIODevice::ReadOnly))
58 m_message = QStringLiteral(
"Cannot open file '%1' for reading").arg(File);
62 m_reader.setDevice(&file);
74 QBuffer buffer(&Data);
75 buffer.open(QBuffer::ReadOnly);
76 m_reader.setDevice(&buffer);
91 bool TorcXMLReader::ReadXML(
void)
93 if (!m_reader.readNextStartElement())
96 QString root = m_reader.name().toString();
98 while (m_reader.readNextStartElement())
99 if (!ReadElement(objects))
101 m_map.insert(root, objects);
108 bool TorcXMLReader::ReadElement(QVariantMap &Map)
110 QString name = m_reader.name().toString();
116 switch (m_reader.readNext())
118 case QXmlStreamReader::Invalid:
119 m_message = QStringLiteral(
"XML error: '%1' at line %2:%3").arg(m_reader.errorString()).arg(m_reader.lineNumber()).arg(m_reader.columnNumber());
121 case QXmlStreamReader::EntityReference:
122 case QXmlStreamReader::Characters:
123 if (!m_reader.isWhitespace())
124 Map.insertMulti(name, m_reader.text().toString());
126 case QXmlStreamReader::StartElement:
127 if (!ReadElement(element))
130 case QXmlStreamReader::EndDocument:
131 case QXmlStreamReader::EndElement:
133 case QXmlStreamReader::NoToken:
134 case QXmlStreamReader::StartDocument:
135 case QXmlStreamReader::ProcessingInstruction:
136 case QXmlStreamReader::Comment:
137 case QXmlStreamReader::DTD:
142 if (!element.isEmpty())
143 Map.insertMulti(name, element);
TorcXMLReader(const QString &File)
QVariantMap GetResult(void) const
bool IsValid(QString &Message) const