I've been trying for a couple of day to read an XML file with Qt using this method (https://github.com/sr105/international_trade/tree/master/large-file-test) , but whereas code looks rather robust, the QXmlStreamReader doesn't read the file at all.
I've modified the code and the XML file a lot of time to figure out where the error was coming from, but the XML is valid (according to the XML validator) , and the program doesn't crash, end unexpectedly, or leaks out. It simply doesn't work.
So by testing some things, I've managed to find one clue : the first use of readNext() returns a StartDocument token ; but any subsequent use returns an invalid token (despite the fact that the XML have been validated) . I've also tried readNextStartElement, same issue.
Here is the relevent code :
void MyXmlStreamReader::processElementsByTagNameHierarchy(QStringList names, fn_type method, void *data) { if (names.isEmpty() || method == 0) return; QString currentElementName = _xml.name().toString(); QString name = names.first(); names.removeFirst(); while (!_xml.atEnd()) { while (_xml.readNextStartElement()) { if (_xml.name() != name) { _xml.skipCurrentElement(); continue; } if (names.isEmpty()) method(*this, data); else processElementsByTagNameHierarchy(names, method, data); while(!(_xml.isEndElement() && _xml.name() == name)) _xml.skipCurrentElement(); } if (_xml.isEndElement() && _xml.name() == currentElementName) break; } } (if you want the complete code, you can have it at the link above)
and the XML file:
<?xml version="1.0" encoding="UTF-8" ?> <pilots> <pilot> <name>Asgore</name> <surname>Dreemurr</surname> <mass>90</mass> </pilot> </pilots> I truly don't understand where the error is coming from...
Thanks to anyone who could help me.
Cordially, Jaxon
No comments:
Post a Comment