Solved Reading a xml file and parsing it
-
This post is deleted! -
@Aashu10
You can read this way.qxmlstreamreader *xmlreader; while(!xmlreader->atEnd()) { if(xmlreader->isStartElement()) { if(xmlreader->name()== "MAIN_HEADER") { xmlreader->readnext(); } else if(xmlreader->name() == "HEADER") { while(!xmlreader->atEnd()) { if(xmlreader->isendelement()) { if(xmlreader->name() == "HEADER") { xmlreader->readNext(); break; } xmlreader->readNext(); } else if(xmlreader->isCharacters()) { xmlreader->readnext(); } else if(xmlreader->isStartElement()) { if(xmlreader->name() == "TITLE") { xmlreader->readNext(); } else if(xmlreader->name() == "AUTHOR") { xmlreader->readNext(); } else if(xmlreader->name() == "NAME") { qstring name=xmlReader->readElementText()) ;// found } ................. else { xmlreader->readNext(); } } else if(xmlreader->isEndElement()) { if(xmlreader->name() == "MAIN_HEADER") { break; } xmlreader->readNext(); } else { xmlreader->readnext(); } } }
-
So i do not have to consider the main tag? <MAIN_HEADER>
-
@Aashu10
I have EDITed the previous post. -
I am very new to Xmlstreamreader, Please bear with me
I am getting a error as " C2039: 'readnext' : is not a member of 'QXmlStreamReader' -
@Aashu10
I edited the code in the text editor. So be careful with the spelling.xmlReader->readNext();
-
Ah there's sytax error, trying real hard to find it out. I'm getting:
" error: C2181: illegal else without matching if"
on line:
else if(xmlreader.isEndElement()). any idea why? -
Probably } before else if(xmlreader.isEndElement()) is missing
-
@Aashu10
We cannot just say if the tag is read or not. it requires careful observations.
Best way is to right the read tags back to .xml file to check if it really read or not . -
Thanks a ton! i think i am near to solving the problem, i have edited the program. You can see what exactly i am doing. I choosing a xml file from a dropdown. and QT parse that XML file. Now when i choose an xml file. Whole program gets stuck.
-
-
Thanks alot! still can't figure out why does my gui hangs.
Can you please tell me what does String holds in:
"QString name=xmlreader.readElementText(); // found"I had a debug there to check, unfortunately my gui is hanging
-
Did you try the test code?
QString name
holds the namejohn
Download this zip file. Build your project and browse for the XML.xml file to find the matched name . -
Thanks for the help! this works too! But i think DOM is turning out to be simpler, i really appriciate your help. don't exactly know how to accept your answer on this forum.
-
@Aashu10
There is nothing like "answer" for particular question . You can Upvote the answer(s) that helped you to solve the issue.
Once your problem is solved please use the Topic Tools button to mark as Solved.
Thank you!