Hello all,
I am trying comment a multiline section of xml to an output file using qxmlstreamwriter. I am in a loop, iterating through my nested structures, and if a structure is noted as "isCommented" then I need to insert a "<!--" then continue writing the XML form of the output. When I get to the end of that structure I need to insert the end comment "-->". The qxmlstreamwriter::writeCharacters(QString) method won't suffice since it picks out the special characters such as "<" and re-interprets them. I have already handled eradicating cases for nested comments... so that isn't an issue (the inner and outer loop are guaranteed to not both be commented) Any ideas for an alternate solution? Below is an example of my code:
...
QXmlStreamWriter writer(&myFile)
for (int i = 0; i < bigStruct.size(); i++){
if (bigStruct.at(i)->isCommented){
//start comment sequence
//insert "<!--"
}
writer.writeStartElement("BigStruct");
for (int j = 0; j < smallerStruct; j++){
if (smallerStruct.at(i)->isCommented){
//start comment sequence
//insert "<!--"
}
writer.writeStartElement("SmallerStruct");
writer.writeTextElement("Stuff", "blah");
writer.writeTextElement("More Stuff", "blah blah blah");
writer.writeEndElement();
if (smallerStruct.at(i)->isCommented){
//end comment sequence
//insert "-->"
}
}
writer.writeEndElement();
if (bigStruct.at(i)->isCommented){
//endcomment sequence
//insert "-->"
}
}
...
...
QXmlStreamWriter writer(&myFile)
for (int i = 0; i < bigStruct.size(); i++){
if (bigStruct.at(i)->isCommented){
//start comment sequence
//insert "<!--"
}
writer.writeStartElement("BigStruct");
for (int j = 0; j < smallerStruct; j++){
if (smallerStruct.at(i)->isCommented){
//start comment sequence
//insert "<!--"
}
writer.writeStartElement("SmallerStruct");
writer.writeTextElement("Stuff", "blah");
writer.writeTextElement("More Stuff", "blah blah blah");
writer.writeEndElement();
if (smallerStruct.at(i)->isCommented){
//end comment sequence
//insert "-->"
}
}
writer.writeEndElement();
if (bigStruct.at(i)->isCommented){
//endcomment sequence
//insert "-->"
}
}
...
To copy to clipboard, switch view to plain text mode
An example XML may look like:
<BigStruct>
<SmallerStruct>
<Stuff>blah</Stuff>
<More Stuff>blah blah blah</More Stuff>
</SmallerStruct>
<!--
<SmallerStruct>
<Stuff>blah</Stuff>
<More Stuff>blah blah blah</More Stuff>
</SmallerStruct>
-->
</BigStruct>
<!--
<BigStruct>
<SmallerStruct>
<Stuff>blah</Stuff>
<More Stuff>blah blah blah</More Stuff>
</SmallerStruct>
</BigStruct>
-->
<BigStruct>
<SmallerStruct>
<Stuff>blah</Stuff>
<More Stuff>blah blah blah</More Stuff>
</SmallerStruct>
<!--
<SmallerStruct>
<Stuff>blah</Stuff>
<More Stuff>blah blah blah</More Stuff>
</SmallerStruct>
-->
</BigStruct>
<!--
<BigStruct>
<SmallerStruct>
<Stuff>blah</Stuff>
<More Stuff>blah blah blah</More Stuff>
</SmallerStruct>
</BigStruct>
-->
To copy to clipboard, switch view to plain text mode
Thanks for your time.
Bookmarks