
Originally Posted by
kabanek
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?
What is this while() loop supposed to do?
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
Attributes are reported in StartElement and not EndElement.
I'm not sure what you want to achieve but I think you are overcomplicating things, try this:
JList<JCss> JTemplate
::readStyles(QXmlStreamReader
&xml,
QString parentId,
QString id
){
JList<JCss> css;
Q_ASSERT(xml.name() == parentId);
while(xml.readNextStartElement() {
if(xml.name() == parentId) {
while(xml.readNextStartElement()){
if(xml.name() == id){
JCss _result;
_result.setName(xml.attributes().value("name").toString());
qDebug() << "Styl:" << xml.name();
_result.setStyle(...); // I don't think readElementText() will work here without using a CDATA section
css.add(_result);
} else xml.skipCurrentElement(); // skip unknown tags
}
xml.skipCurrentElement(); // read until end of parentId tag
} else xml.skipCurrentElement(); // skip unknown tags
}
return css;
}
JList<JCss> JTemplate::readStyles(QXmlStreamReader &xml, QString parentId, QString id )
{
JList<JCss> css;
Q_ASSERT(xml.name() == parentId);
while(xml.readNextStartElement() {
if(xml.name() == parentId) {
while(xml.readNextStartElement()){
if(xml.name() == id){
JCss _result;
_result.setName(xml.attributes().value("name").toString());
qDebug() << "Styl:" << xml.name();
_result.setStyle(...); // I don't think readElementText() will work here without using a CDATA section
css.add(_result);
} else xml.skipCurrentElement(); // skip unknown tags
}
xml.skipCurrentElement(); // read until end of parentId tag
} else xml.skipCurrentElement(); // skip unknown tags
}
return css;
}
To copy to clipboard, switch view to plain text mode
Bookmarks