66 lines
1.4 KiB
C++
66 lines
1.4 KiB
C++
|
|
#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;
|
|||
|
|
}
|