[Solved]QDomDocument
-
wrote on 1 Jun 2012, 09:48 last edited by
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?
-
wrote on 1 Jun 2012, 12:31 last edited by
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
Frédéric -
wrote on 1 Jun 2012, 15:07 last edited by
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? -
wrote on 2 Jun 2012, 18:46 last edited by
Just a blind guess: The document contains HTML character entities like ä or ¼. If you do not include the definition of these entities into your document or make it available to be loaded by the parser.
-
wrote on 3 Jun 2012, 07:52 last edited by
Some hints on how I can do that would be a huge help .Thank you for your help.
-
wrote on 3 Jun 2012, 11:30 last edited by
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("xhtml-test.xml"); xmlFile.open(QIODevice::ReadOnly); QString errorMessage; int errorLine, errorColumn; QDomDocument doc; bool xmlOk = doc.setContent(&xmlFile, &errorMessage, &errorLine, &errorColumn); xmlFile.close(); if(xmlOk) qDebug() << "Loading XML file ok"; else 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.
-
wrote on 3 Jun 2012, 11:47 last edited by
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" .
-
wrote on 3 Jun 2012, 11:49 last edited by
@for(item in outputSummary){
//this is the line where the parser stops
if(outputSummary.hasOwnProperty(item)){if(summary[item].coords.length){ docSource += "\t\t\t\tcoords[\"" + item + "\"] = \"" + summary[item].coords.join(" ") + "\";\n"; }
}@
-
wrote on 3 Jun 2012, 12:21 last edited by
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" .
-
wrote on 3 Jun 2012, 20:55 last edited by
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.
-
wrote on 4 Jun 2012, 06:02 last edited by
Thx...in the end I used regular expresions (QRegExp) to extract what I need.
2/11