[Solved]QDomDocument
-
-
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? -
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("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.
-
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
if(outputSummary.hasOwnProperty(item)){if(summary[item].coords.length){ docSource += "\t\t\t\tcoords[\"" + item + "\"] = \"" + summary[item].coords.join(" ") + "\";\n"; }
}@
-
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.