开始加入类来处理各种元素

Signed-off-by: facat@lab.com <facat@lab.com>
This commit is contained in:
facat@lab.com
2014-11-22 11:32:12 +08:00
parent 3a555bd2c1
commit f502f0dc62
8 changed files with 182 additions and 3 deletions

View File

@@ -0,0 +1,65 @@
#include "elementhashtable.h"
//#include <iostream>
ElementHashtable::ElementHashtable(QObject *parent) :
QObject(parent)
{
}
bool ElementHashtable::child(QXmlStreamReader &reader)
{
QStringRef elementName;
elementName=reader.name();
BasicElementInfo *pointer=NULL;
if(elementName.toString()=="SubControlArea")
{
SubControlArea sa;
pointer=&sa;
sa.parse(reader);
}
if(pointer)
{
this->eleHT[elementName.toString()]=*pointer;
}
return true;
}
bool ElementHashtable::parse(const QString& xmlPath)
{
QFile xmlFile(xmlPath);
int loop=0;
if(xmlFile.open(QFile::ReadOnly))
{
QXmlStreamReader reader(&xmlFile);
while(!reader.atEnd() && !reader.hasError())
{
reader.readNext();
if(reader.isStartElement())
{
if(reader.name()=="RDF")//不要读<rdf:RDF xmlns:rdf="http://www.w3.org/1999/ …… 这样一堆东西
{
continue;
}
this->child(reader);//处理根元素下的第一级子元素也就是Substation这一类。
}
loop++;
if(loop>20){
break;
}
}
if(reader.hasError())
{
qDebug()<<reader.errorString()<<"\n";
qDebug()<<"line number "<<reader.lineNumber()<<"\n";
}
xmlFile.close();
}
return true;
}