[Solved]XML readproblems
-
Look at this: it seems that your input is not complete when you are trying to parse the XML document.
-
Thanks
I'll Try this tomorrow.I thought this would be enough
@QXmlStreamReader s(&in);@ -
Well, it depends what is you in object. If it's a file on disk, I agree with you. However if you're downloading the file for instance with QNetworkAccessManager / QNetworkReply, you better wait till the file is completely downloaded and written.
I'm pretty sure there's an example of this somewhere...
Edit : found what I wanted, when I was trying to do such a thing this thread and this one as well helped me.
-
I got the file in the same folder as the application on the disk but I will try with another xml file
-
This is the problem
@s.readElementText();@
anyone
pls -
The readElementText() method uses readElementText( ErrorOnUnexpectedElement ).
As far as I understand this error means that your file (assuming the reading of the full file is OK) doesn't contain valid XML: it tries to find the corresponding EndElement till the end of the file but cannot...Why don't you start trying to read a simple xml, like this one?
-
I did that with a simple xml file and I tried your exampel to but same error.
This is a big problem now. -
It means that you're using the readElementText in a wrong way... I'm afraid I cannot help you much more than I already tried. I'm not a big QXmlStreamReader user.
-
thank you for your help.
Is it easier to use sax or dom to get the values in the xml -
Got it to work
@void MainWindow::init()
{//QFile file("C:/testprojekt/filesXML/cache.xml"); //QFile file("C:/testprojekt/filesXML/parts.xml"); QFile file("C:/testprojekt/filesXML/simple.xml"); if (file.exists()) qDebug() << file.fileName(); else qDebug() << "NO " + file.fileName(); file.open(QIODevice::ReadOnly); QXmlStreamReader xml_stream(&file); while (!xml_stream.atEnd() && !xml_stream.hasError()) { if (xml_stream.isStartElement() && xml_stream.name() =="description") ui->textBrowser->append( + "<" + xml_stream.name().toString() + ">" + xml_stream.readElementText()); xml_stream.readNext(); } ui->textBrowser->append("-------------------------"); xml_stream.clear(); file.close();
}@