• Hy...I use QDomDocument::setContent(QString) with a string long of over 1KK characters.The problem is the the QDomDocument retains only 78K characters.Is it because of a limit or it can be something else?

  • hello

    It's strange. I just tested with a xml file (351Ko).
    I read the file, use setContent, and save the file.

    Do you test if the return value of the function is true ?

    Do you test if your string containt a well formed xml document ?

    Best regards

  • The return value is false.This is the error message:
    "error occurred while parsing reference" .The document type is :
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> .What can I do to remediate the problem?

  • Just a blind guess: The document contains HTML character entities like &auml; or &frac14;. If you do not include the definition of these entities into your document or make it available to be loaded by the parser.

  • Some hints on how I can do that would be a huge help .Thank you for your help.

  • The first step is to determine what really causes the error:

    This snippet will show you the exact line and column with an error message where the parser bailed out:

    #include <QtCore/QCoreApplication>
    #include <QFile>
    #include <QDomDocument>
    #include <QDebug>

    int main(int argc, char *argv[])
    QCoreApplication a(argc, argv);

    QFile xmlFile&#40;"xhtml-test.xml"&#41;;
    QString errorMessage;
    int errorLine, errorColumn;
    QDomDocument doc;
    bool xmlOk = doc.setContent(&xmlFile, &errorMessage, &errorLine, &errorColumn);
        qDebug() << "Loading XML file ok";
        qDebug() << "XML Error at line" << errorLine << "column" << errorColumn << ":" << errorMessage;
    return 0;


    Another option would be to use a tool like xmllint, wich is part of the "libxml":http://xmlsoft.org/ package.

  • I 've done that but when I open the XHTML file with notepad++ that line is empty,what program should I use to open the XHTML file?The error is "error occurred while parsing reference" .

  • @for(item in outputSummary){
    //this is the line where the parser stops

     docSource += &quot;\t\t\t\tcoords[\&quot;&quot; + item + &quot;\&quot;] = \&quot;&quot; + summary[item].coords.join(&quot; &quot;) + &quot;\&quot;;\n&quot;;


  • When I put setContent() with a QString containing the code I get the error at line 989 but when I put setContent() with a .txt file the erorr is at line 1557 column 64.Here is line 1556 and 1557:
    @//line 1556:
    <input type="hidden" value="ſtergerea grupei" id="group_title_delete"/>
    //Line 1557:
    <input type="hidden" value="/game.php" village=57564&screen=overview_villages&mode=combined&group=0&partial=1" id="start_edit_group_link"/>@

    The value attribute in line 1556 should be: "Ștergerea grupei" .

  • Some encoding issue, I would say. Parsing XML documents from a QString is suboptimal, at best. QString is always a Unicode UTF-16 representation of the enclosed data. The contents can be contradictory to the encoding claimed in the XML header.

    If you construct your XML manually, like here, concatenating QStrings you may run into some validity issues sooner or later (escaping of < and the like comes into mind). I would recommend using the XML stream classes to create the XML. It takes care of proper encoding. You can stream into a QByteArray or a file and pass that to the DOM classes.

  • Thx...in the end I used regular expresions (QRegExp) to extract what I need.

Log in to reply

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