Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How do I read the text of an element using QXmlDefaultHandler
Because @QXmlDefaultHandler::startElement( const QString&, const QString&, const QString &name, const QXmlAttributes &attrs )@
Only gives namespace, name and attributes, I do not see how I can get textValue bellow using the QXmlDefaultHandler SAX parser.
Hi and welcome to devnet,
Are you only reading your xml file ? If so you don't need to use QXmlDefaultHandler, QXmlStreamReader provides everything you need
Hope it helps
Basically, it is in a school assignment that pointed us to http://www.digitalfanatics.org/projects/qt_tutorial/chapter09.html to use as a reference on how to implement. this page does use QXmlDefaultHandler but it does not parse text of elements.
So unless it is not possible to use QXmlDefaultHandler to read the text elements (even if it is cumbersome), I would rather stick to to it.
It appears that there is also
@QXmlDefaultHandler::characters(const QString &ch) @
which is called after
@QXmlDefaultHandler::startElement( const QString&, const QString&, const QString &name, const QXmlAttributes &attrs )@
And contains the text.
One has to raise flag in startElement(...) and then check the flag in characters(...) to read the text from the ch parameter.
It is documented in the Reference but I somehow missed it.