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. unexpected end of file with QDomDocument
Qt 6.11 is out! See what's new in the release blog

unexpected end of file with QDomDocument

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 2.2k Views 2 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.
  • F Offline
    F Offline
    Fangry
    wrote on last edited by
    #1

    Hi every one,

    I've got a problem with QDomDocument.

    When I use the method setContent with an xml file I get the error "unexpected end of file line 1 column 1"

    This is a part of my source code

    int xmlDom::parseXmlWeapon(QString nomArme, st_Arme *armeOut)
    {
        m_domDocument = new QDomDocument("Weapon");
    
        m_xmlFileName = nomArme.append(".xml");
    
        if(!openFileForReading())
        {
            return -1;
        }
        QByteArray text = m_xmlFile->readAll();
        qDebug(text);
        int errorLine, errorColumn;
        QString ErrorMessage;
        if(!m_domDocument->setContent(m_xmlFile, true, &ErrorMessage, &errorLine,&errorColumn))
        {
            return -1;
        }
    ... 
    }
    

    and this is my xml file that I want to extract information.

    <?xml version="1.0" encoding="UTF-8"?>
    <Arme>
       <nom>baton</nom>
       <degats>30</degats>
       <vitesse>10</vitesse>
       <forceRequise>4</forceRequise>
       <mode1>CONTONDANT</mode1>
       <mode2>NA</mode2>
       <categorie>Hast</categorie>
       <special>Deux main</special>
       <solidite>11</solidite>
       <fracassement>0</fracassement>
       <presence>30</presence>
    </Arme>
    
    1 Reply Last reply
    0
    • F Offline
      F Offline
      Fangry
      wrote on last edited by
      #2

      I already read some other forum but it does not bring the right solution.

      I work on QtCretor on Windows 10 with mingw

      Thank you very much

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

        Hi and welcome to devnet,

        With QByteArray text = m_xmlFile->readAll();, you're reading the file completely. Then right after that you call m_domDocument->setContent on the same file, which current position will be at the end of the file. So either use the content fo your textvariable to put into m_domDocument or reset the position of the file before using it to load m_domDocument.

        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

        • Login

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