Using custom XmlContentHandler for reading QDomDocument
Hi, i want use custom XmlReader for reading in QDomDocument. But Dom ignoring my Handler.
- #include <QtXml>
- #include <QDebug>
- {
- public:
- virtual bool startElement ( const QString & namespaceURI, const QString & localName, const QString & qName, const QXmlAttributes & atts );
- };
- bool
- MyHandler::startElement ( const QString & namespaceURI, const QString & localName, const QString & qName, const QXmlAttributes & atts )
- {
- qDebug() << localName;
- return true;
- }
- int main()
- {
- MyHandler *handler = new MyHandler;
- reader->setContentHandler(handler);
- reader->setErrorHandler(handler);
- QDomDocument dom;
- dom.setContent(source, reader);
- file.close();
- return 0;
- }
This code is reading file simple.xml and create DOM object. But it don’t using MyHandler class for parsing. The function MyHandler::startElement is not called. Why this happened?
2 replies
domtest.pro:
- TEMPLATE = app
- TARGET =
- DEPENDPATH += .
- INCLUDEPATH += .
- QT += xml
- # Input
- SOURCES += domtest.cpp
simple.xml (but you can use any valid xml):
- <h1 a="123" b="345">
- <h2 c="testing">
- </h2>
- </h1>
You must log in to post a reply. Not a member yet? Register here!


