[SOLVED] QXMLStreamReader invalid token (0n1)



  • Dear All

    I am trying to parse xml files using QXMLStreamReader however Qt continues to say (displayed in the locals and expressions view in debug mode) that the tokens are invalid and stops parsing.

    This is a section of the code:
    @QFile* file = new QFile(filePath);
    file->open(QIODevice::ReadOnly);
    QXmlStreamReader xml(file);
    while(!xml.atEnd() &&!xml.hasError()) {
    QXmlStreamReader::TokenType token = xml.readNext();@

    This a section of the anonymized XML:

    @<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
    <v1:Dos xmlns:v1="http://www.dd.be/ccc/eee/v1" xmlns:ns3="http://www.dd.be/ccc/fff/v1" xmlns:ns4="http://www.dd.be/ccc/gg/v1" xmlns:ns5="http://www.dd.be/ccc/hhh" xmlns:ns2="http://www.dd.be/ccc/pp/v1">
    <v1:Dossier Id="1234567" Versie="123">
    ns2:Eigenaar/@

    Could anybody suggest me what can be wrong?
    If I need to post additional code or XML data please contact me.

    Kind regards
    Hatchi


  • Lifetime Qt Champion

    Hi,

    Could you post a complete XML example ?
    Also what are your Qt version and OS ?



  • Dear SGalst

    I think I found what the problem may be. This is the code which I used for iterating over the XML files:
    @QDirIterator it (directory);
    while (it.hasNext())
    {
    it.next();
    qDebug()<<it.filePath()+ "/" +it.fileName();
    parseXML(it.filePath()+"/"+ it.fileName());
    }@

    However when I use QDebug to print out I get for the file name always a .

    @QWindowsNativeFileDialogBase::selectNameFilter: Invalid parameter 'Directories' not found in 'All Files (*)'.
    "E:/proeftuin/vac_77777827/../.." @

    Afterwards when I try to parse the file I get the following error:
    @"Premature end of document."
    at line 1 , column 0
    Error type 4 @

    I also tried to use QDir and entryList but the file names were still a .

    What can cause this problem?

    Kind regards and thanks
    Hatchi


  • Lifetime Qt Champion

    The problem is that you are trying to parse the . and .. path which are respectively "current dir" and "parent dir"



  • Could you give me a hint what exactly is wrong in my usage of QDirIterator? I request the file name from the iterator and append it to the file path ... Is this wrong and causing the problem?


  • Lifetime Qt Champion

    Add a check for your file name, if it's either . or .. do not parse them.

    Also IIRC filePath() will give you the complete path including the filename.



  • This solved my problem:
    @ QDirIterator it (directory, QDir::NoDotAndDotDot | QDir::Files);
    parseXML(it.filePath());@

    Thanks a lot!!
    Hatchi


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.