Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Dom document set content error



  • Hi
    I want to use xml with dom approach with QT. the first line of xml file is this
    <?xml version="1.0" encoding="utf-16">
    this line automatically generated with dom document
    but the problem arises when I want to read the content. when I use setContent method it breaks. on this line and first column. if I remove this line everything is fine. what's should i do?
    Qt version 5.2
    OS:windows 7 x64
    compiler :VS2012



  • Could you please post a code snipplet and a sample XML file?



  • <?xml version=“1.0” encoding=“UTF-16”>
    <Tables>
    <Table Version="1.0" CreateDate="2014/01/01" isDelete="false" ModifiedDate="">
    <me>1</me>
    <you>2</you>
    </Table>
    <Table Version="1.0" CreateDate="2014/01/01" isDelete="false" ModifiedDate="">
    <me>1</me>
    <you>2</you>
    </Table>
    </Tables>

    @QDomDocument document;
    QFile xmlFile(QString::fromUtf16(tablePath));
    QByteArray xml;
    xml=xmlFile.readAll();
    xmlFile.close();
    QString errorMsg ;
    int errorLine , errorColumn ;
    if(!document.setContent(xml,&errorMsg,&errorLine,&errorColumn)){
    if(errorMsg!="unexpected end of file"){
    result=-1;
    return result;
    }
    }
    QDomNode root= document.namedItem(rootName);
    QDomNodeList nodeList=document.elementsByTagName(rootName);
    //the rest of code@


  • Qt Champions 2017

    What is the error you are observing ?

    Can you try something like this ?

    @ QFile file(fileName);
    if (!file.open(QFile::ReadOnly | QFile::Text)) {
    qDebug() << "Error " << endl;
    return false;
    }

    QString err;
    int errL, errC;
    
    QDomDocument doc;
    if (!doc.setContent(&file, false, &err, &errL, &errC))@


  • Hello Paytam,

    The xml that u have posted on forum is invalid.
    because i can't see an ending tag of
    Table..where is that ???


Log in to reply