abhi8888
11th June 2015, 10:46
i have already made an xml.
but when i m reading it it shows error while setiing in device.
my code is:--
void XMLReader::read(QString fileName) //// file name is the xml name
{
QFile xmlFile(fileName);
xmlFile.open(QIODevice::ReadOnly);
qDebug()<<"///////////////////////////"<<xmlFile.isOpen(); ------>> shows its open
xml.setDevice(&xmlFile); ----->> shows error here
if (xml.readNextStartElement() && xml.name() == "Summary")
processSummary();
if (xml.tokenType() == QXmlStreamReader::Invalid)
xml.readNext();
if (xml.hasError()) {
xml.raiseError();
qDebug() << "error" << endl;
}
}
void XMLReader::processSummary()
{
if(!xml.isStartElement() || xml.name()!= "Summary")
return;
QString blankspaces;
QString blanklines;
QString words;
QString with_hash;
while (xml.readNextStartElement()) {
if (xml.name() == "no_of_blank_spaces")
blankspaces=xml.text().toString();
if (xml.name() == "no_of_blank_lines")
blanklines=xml.text().toString();
if (xml.name() == "no_of_words")
words=xml.text().toString();
if (xml.name() == "no_of_lines_starting_with_hash")
with_hash= xml.text().toString();
}
qDebug()<<"please answer" <<blankspaces << endl;
}
my XML is---
<?xml version="1.0" encoding="UTF-8"?>
<Summary>
<no_of_blank_spaces>13</no_of_blank_spaces>
<no_of_blank_lines>8</no_of_blank_lines>
<no_of_words>16</no_of_words>
<no_of_lines_starting_with_hash>2</no_of_lines_starting_with_hash>
</Summary>
it shos the output ""error""..
please help
but when i m reading it it shows error while setiing in device.
my code is:--
void XMLReader::read(QString fileName) //// file name is the xml name
{
QFile xmlFile(fileName);
xmlFile.open(QIODevice::ReadOnly);
qDebug()<<"///////////////////////////"<<xmlFile.isOpen(); ------>> shows its open
xml.setDevice(&xmlFile); ----->> shows error here
if (xml.readNextStartElement() && xml.name() == "Summary")
processSummary();
if (xml.tokenType() == QXmlStreamReader::Invalid)
xml.readNext();
if (xml.hasError()) {
xml.raiseError();
qDebug() << "error" << endl;
}
}
void XMLReader::processSummary()
{
if(!xml.isStartElement() || xml.name()!= "Summary")
return;
QString blankspaces;
QString blanklines;
QString words;
QString with_hash;
while (xml.readNextStartElement()) {
if (xml.name() == "no_of_blank_spaces")
blankspaces=xml.text().toString();
if (xml.name() == "no_of_blank_lines")
blanklines=xml.text().toString();
if (xml.name() == "no_of_words")
words=xml.text().toString();
if (xml.name() == "no_of_lines_starting_with_hash")
with_hash= xml.text().toString();
}
qDebug()<<"please answer" <<blankspaces << endl;
}
my XML is---
<?xml version="1.0" encoding="UTF-8"?>
<Summary>
<no_of_blank_spaces>13</no_of_blank_spaces>
<no_of_blank_lines>8</no_of_blank_lines>
<no_of_words>16</no_of_words>
<no_of_lines_starting_with_hash>2</no_of_lines_starting_with_hash>
</Summary>
it shos the output ""error""..
please help