Qt World Summit: Register Today!

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”>
    <Table Version="1.0" CreateDate="2014/01/01" isDelete="false" ModifiedDate="">
    <Table Version="1.0" CreateDate="2014/01/01" isDelete="false" ModifiedDate="">

    @QDomDocument document;
    QFile xmlFile(QString::fromUtf16(tablePath));
    QByteArray xml;
    QString errorMsg ;
    int errorLine , errorColumn ;
    if(errorMsg!="unexpected end of file"){
    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