unexpected end of file with QDomDocument
Unsolved
General and Desktop
-
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>
-
Hi and welcome to devnet,
With
QByteArray text = m_xmlFile->readAll();
, you're reading the file completely. Then right after that you callm_domDocument->setContent
on the same file, which current position will be at the end of the file. So either use the content fo yourtext
variable to put intom_domDocument
or reset the position of the file before using it to loadm_domDocument
.