Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QXMLStreamReader invalid token (0n1)
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QXMLStreamReader invalid token (0n1)

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 4.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hatchi
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hatchi
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • H Offline
            H Offline
            Hatchi
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • H Offline
                H Offline
                Hatchi
                wrote on last edited by
                #7

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

                Thanks a lot!!
                Hatchi

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved