parent
f502f0dc62
commit
ccc4c1d90c
|
|
@ -1,5 +1,5 @@
|
||||||
#include "elementhashtable.h"
|
#include "elementhashtable.h"
|
||||||
//#include <iostream>
|
#include <iostream>
|
||||||
ElementHashtable::ElementHashtable(QObject *parent) :
|
ElementHashtable::ElementHashtable(QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
|
|
@ -12,12 +12,12 @@ bool ElementHashtable::child(QXmlStreamReader &reader)
|
||||||
QStringRef elementName;
|
QStringRef elementName;
|
||||||
elementName=reader.name();
|
elementName=reader.name();
|
||||||
BasicElementInfo *pointer=NULL;
|
BasicElementInfo *pointer=NULL;
|
||||||
if(elementName.toString()=="SubControlArea")
|
// if(elementName.toString()=="SubControlArea")
|
||||||
{
|
// {
|
||||||
SubControlArea sa;
|
// SubControlArea sa;
|
||||||
pointer=&sa;
|
// pointer=&sa;
|
||||||
sa.parse(reader);
|
// sa.parse(reader);
|
||||||
}
|
// }
|
||||||
|
|
||||||
if(pointer)
|
if(pointer)
|
||||||
{
|
{
|
||||||
|
|
@ -49,7 +49,7 @@ bool ElementHashtable::parse(const QString& xmlPath)
|
||||||
}
|
}
|
||||||
loop++;
|
loop++;
|
||||||
if(loop>20){
|
if(loop>20){
|
||||||
break;
|
// break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -60,6 +60,5 @@ bool ElementHashtable::parse(const QString& xmlPath)
|
||||||
}
|
}
|
||||||
xmlFile.close();
|
xmlFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ public:
|
||||||
private:
|
private:
|
||||||
bool child(QXmlStreamReader &reader);
|
bool child(QXmlStreamReader &reader);
|
||||||
QHash<QString,BasicElementInfo> eleHT;
|
QHash<QString,BasicElementInfo> eleHT;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <elementhashtable.h>
|
#include <elementhashtable.h>
|
||||||
|
#include "regexextract.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication a(argc, argv);
|
QCoreApplication a(argc, argv);
|
||||||
ElementHashtable eleReader;
|
ElementHashtable eleReader;
|
||||||
eleReader.parse("D:/Project/佛山项目/佛山收资/exportmodel_zwyth/df8003/df8600/exportfiles/exportmodel_zwyth.xml");
|
// eleReader.parse("D:/Project/佛山项目/佛山收资/exportmodel_pw/df8003/df8600/exportfiles/exportmodel_pw.xml");
|
||||||
|
RegexExtract regexExt;
|
||||||
|
regexExt.extract("D:/Project/佛山项目/佛山收资/exportmodel_pw/df8003/df8600/exportfiles/exportmodel_pw.xml");
|
||||||
|
regexExt.exportBlocks("ConnectivityNode.xml");
|
||||||
std::cout<<"Finished."<<std::endl;
|
std::cout<<"Finished."<<std::endl;
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,75 @@
|
||||||
|
#include "regexextract.h"
|
||||||
|
#include <iostream>
|
||||||
|
RegexExtract::RegexExtract()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool RegexExtract::endsWith(const QString& line,const QString& eleName)
|
||||||
|
{
|
||||||
|
QString t=line.trimmed();
|
||||||
|
return t.startsWith(QString("</cim:")+eleName+QString(">"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegexExtract::exportBlocks(const QString& path)
|
||||||
|
{
|
||||||
|
QFile file(path);
|
||||||
|
std::cout<<"writing..."<<std::endl;
|
||||||
|
if(file.open(QFile::WriteOnly))
|
||||||
|
{
|
||||||
|
QTextStream writer(&file);
|
||||||
|
for(QStringList::iterator ite=this->blocks.begin();
|
||||||
|
ite!=this->blocks.end();
|
||||||
|
ite++)
|
||||||
|
{
|
||||||
|
writer<<*ite;
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RegexExtract::extract(const QString& xmlPath)
|
||||||
|
{
|
||||||
|
QFile file(xmlPath);
|
||||||
|
QString line;
|
||||||
|
QString block;
|
||||||
|
bool isInner=false;
|
||||||
|
if(file.open(QFile::ReadOnly))
|
||||||
|
{
|
||||||
|
QTextStream reader(&file);
|
||||||
|
while(!reader.atEnd())
|
||||||
|
{
|
||||||
|
line=reader.readLine();
|
||||||
|
// std::cout<<line.toStdString()<<std::endl;
|
||||||
|
if(!isInner && this->startsWith(line,"ConnectivityNode"))
|
||||||
|
{
|
||||||
|
block="";
|
||||||
|
isInner=true;
|
||||||
|
}
|
||||||
|
if(isInner)
|
||||||
|
{
|
||||||
|
block=block+line+QString("\n");
|
||||||
|
}
|
||||||
|
if(isInner && this->endsWith(line,"ConnectivityNode"))
|
||||||
|
{
|
||||||
|
isInner=false;
|
||||||
|
this->blocks.push_back(block);
|
||||||
|
// std::cout<<block.toStdString()<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool RegexExtract::startsWith(const QString& line,const QString& eleName)
|
||||||
|
{
|
||||||
|
QString t=line.trimmed();
|
||||||
|
return t.startsWith(QString("<cim:")+eleName+QString(" "));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
#ifndef REGEXEXTRACT_H
|
||||||
|
#define REGEXEXTRACT_H
|
||||||
|
#include <QString>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
class RegexExtract
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RegexExtract();
|
||||||
|
bool extract(const QString& xmlPath);
|
||||||
|
void exportBlocks(const QString& path);
|
||||||
|
protected:
|
||||||
|
bool startsWith(const QString& line,const QString& eleName);
|
||||||
|
bool endsWith(const QString& line,const QString& eleName);
|
||||||
|
QStringList blocks;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // REGEXEXTRACT_H
|
||||||
|
|
@ -19,12 +19,14 @@ TEMPLATE = app
|
||||||
SOURCES += main.cpp \
|
SOURCES += main.cpp \
|
||||||
elementhashtable.cpp \
|
elementhashtable.cpp \
|
||||||
subcontrolarea.cpp \
|
subcontrolarea.cpp \
|
||||||
BasicElementInfo.cpp
|
BasicElementInfo.cpp \
|
||||||
|
regexextract.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
elementhashtable.h \
|
elementhashtable.h \
|
||||||
BasicElementInfo.h \
|
BasicElementInfo.h \
|
||||||
subcontrolarea.h
|
subcontrolarea.h \
|
||||||
|
regexextract.h
|
||||||
|
|
||||||
#release{
|
#release{
|
||||||
#DEFINES += QT_NO_DEBUG_OUTPUT
|
#DEFINES += QT_NO_DEBUG_OUTPUT
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue