0
QT MessageHandler (줄, 열, 설명 등)가 XML 파일에 하나 이상의 오류가 있기 때문에 유효성 검사가 실패한 경우 해결책을 찾으려고합니다. XML 파일에서 발생하는 첫 번째 오류뿐만 아니라 XML 데이터의 모든 오류를 표시합니다.QT XML validation 오류 처리
예 : I 선에 에러가 65 (참조 : PIC)
을 그러나이 오차는 줄 수도있다 : 78,83,95하지만 그것만을 도시 보이지 복용량 첫 번째.
이 경우 해결 방법이 있습니까? 그리고 그렇다면 어떻게?
내 코드는 다음과 같습니다
MessageHandler messageHandler;
QFile xsdfile("....xsd");
xsdfile.open(QIODevice::ReadOnly);
QXmlSchema schema;
schema.setMessageHandler(&messageHandler);
bool errorOccurred = false;
if (schema.load(&xsdfile, QUrl::fromLocalFile(xsdfile.fileName())) == false)
errorOccurred = true;
else
{
QXmlSchemaValidator xmlvalidator(schema);
QFile xmlfile("......xml");
xmlfile.open(QIODevice::ReadOnly);
if (!xmlvalidator.validate(&xmlfile, QUrl::fromLocalFile(xmlfile.fileName())))
errorOccurred = true;
xmlfile.close();
}
xsdfile.close();
if (errorOccurred) {
QString qs = messageHandler.statusMessage();
cout << "Line: " << messageHandler.line() << "\n" << "Row: " << messageHandler.column() << "\n" << "ErrorMessage: ";
std::cout << qs.toUtf8().constData() << std::endl;
return -1;
}
else {
return 0;
}
그리고 내에 messageHandler 클래스는 다음과 같습니다
class MessageHandler : public QAbstractMessageHandler
{
public:
MessageHandler()
: QAbstractMessageHandler(0)
{
}
QString statusMessage() const
{
return m_description;
}
int line() const
{
return m_sourceLocation.line();
}
int column() const
{
return m_sourceLocation.column();
}
protected:
virtual void handleMessage(QtMsgType type, const QString &description,
const QUrl &identifier, const QSourceLocation &sourceLocation)
{
Q_UNUSED(type);
Q_UNUSED(identifier);
m_description = description;
m_sourceLocation = sourceLocation;
}
private:
QString m_description;
QSourceLocation m_sourceLocation;
};
감사합니다 :)
포스트 코드. – has
모든 오류를 잡기 위해 사용자 정의 유효성 검사기를 작성해야한다고 생각합니다. 대학 프로젝트에서 사용한 예를 게시 할 수 있습니다. 따라서 필요에 따라 수정할 수 있습니다. – has