hi,
I'm trying to parse XML file with SAX, but my program started looping. Here is my function:
void JTemplate
::readStyles(QXmlStreamReader
&xml,
QString parentId,
QString id, JList<JCss>
&css
) {
if (xml.name() == parentId)
{
qDebug()<<"Parsuje: "<<parentId;
while (!(xml.name() == parentId && xml.tokenType() == QXmlStreamReader::EndElement))
{
xml.readNext();
JCss _result;
_result.setName(xml.attributes().value("name").toString());
qDebug()<<"Nazwa stylu Css to: "<<_result.getName();
xml.readNext();
while (!(xml.name() == id && xml.tokenType() == QXmlStreamReader::EndElement))
{
qDebug()<<"Styl: " << xml.name().toString();
_result.setStyle(toCssStyle(xml.name().toString()), xml.readElementText());
}
css.add(_result);
xml.readNext();
continue;
}
}
}
void JTemplate::readStyles(QXmlStreamReader &xml, QString parentId, QString id, JList<JCss> &css)
{
if (xml.name() == parentId)
{
qDebug()<<"Parsuje: "<<parentId;
while (!(xml.name() == parentId && xml.tokenType() == QXmlStreamReader::EndElement))
{
xml.readNext();
JCss _result;
_result.setName(xml.attributes().value("name").toString());
qDebug()<<"Nazwa stylu Css to: "<<_result.getName();
xml.readNext();
while (!(xml.name() == id && xml.tokenType() == QXmlStreamReader::EndElement))
{
qDebug()<<"Styl: " << xml.name().toString();
_result.setStyle(toCssStyle(xml.name().toString()), xml.readElementText());
}
css.add(_result);
xml.readNext();
continue;
}
}
}
To copy to clipboard, switch view to plain text mode
This function was written to parese parts of XML file like:
<visited>
<link name="bink1_visited">
<FontColor>red</FontColor>
<FontColor2>green</FontColor2>
</link>
</visited>
<visited>
<link name="bink1_visited">
<FontColor>red</FontColor>
<FontColor2>green</FontColor2>
</link>
</visited>
To copy to clipboard, switch view to plain text mode
When I use this function for example
readStyles(_xml, "visited", "link", CssAnchorVisited);
readStyles(_xml, "visited", "link", CssAnchorVisited);
To copy to clipboard, switch view to plain text mode
the loop
while (!(xml.name() == id && xml.tokenType() == QXmlStreamReader::EndElement))
while (!(xml.name() == id && xml.tokenType() == QXmlStreamReader::EndElement))
To copy to clipboard, switch view to plain text mode
is working indefinitely. Why? What do I do wrong?
And the second thing, I cannot read arguments (in my code "name") in line:
_result.setName(xml.attributes().value("name").toString());
_result.setName(xml.attributes().value("name").toString());
To copy to clipboard, switch view to plain text mode
ps. Sory for my English :-) I'm still learning
Bookmarks