unexpected end of file with QDomDocument



  • 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>
    


  • 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


  • Lifetime Qt Champion

    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.


Log in to reply
 

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