[SOLVED] QXmlDomDocument parsing fails to read processing instruction
-
I am trying to read an xml string which is loaded from a file and I am getting an invalid character in the processing instruction. Why is this happening?
My xml is:
@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item id="item1">item1 description</item>
<item id="item2">item2 description</item>
<item id="item3">item3 description</item>
</root>
@This is my function:
@
void readXml(QIODevice* device)
{
int line, col;
QString msg;
QDomDocument doc;
if (doc.setContent(device, &msg, &line, &col))
{
qDebug() << "Success";
}
else
{
qDebug() << QString("%1\n%2\n%3").args(msg, QString::number(line), QString::number(col)));
}
}
@Is there something I am doing wrong here? I need to be able to read this xml string. I cannot change it as this is comming from an external source.
Any help would be greatly appreciated.
-
If the snippet you provided is exactly what you 're using, then line 6 is wrong: setContent expects a pointer on a
QIODevice
, you're providing aQIODevice**
... -
@Johan: Sorry that was a typo. I have updated the post with corrected parameter.
I have had to simplify my example as I cannot use the real code on here due to NDA. I am just confused why the QDomDocument does not seem to be able to handle the quotes in the processing instruction of the xml.
-
I am just confused why the QDomDocument does not seem to be able to handle the quotes in the processing instruction of the xml.
Well, it definitly does handle this, I use it every day. Could you give us information on the Qt version and platform you're using?
Another thing may be the XML document itself: it is is using an exotic encoding for the quotes, and then claims it is UTF-8... just a wild shot.
-
I am using QtCreator 3.1.2 with Qt 5.3.1 on a Mac OSX pc running the latest OS with all patches. I am compiling with the C++11 compiler flags. I am editing the xml file in QtCreator as a resource file so dont think the quotes would be anything outher than the normal double quotes.
-
Hey,
I have figured out what my problem was. I have got code that checks if a custom config file exists and if not copies the resource one to disk. However the first time I ran this it put a broken xml file. The broken xml file had " instead of just " as it was copied from code originally. Now because the file existed it was not using my updated version. I have now resolved it and my execution now works as expected.