title: Multiline comment with QXmlStreamWriter
body: <p>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 "&lt; ! - -" (without spaces)
  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 "&lt;" 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:</p>
  
  <pre><code>...
  QXmlStreamWriter writer(&amp;myFile)
  
  for (int i = 0; i &lt; bigStruct.size(); i++){
  
    if (bigStruct.at(i)-&gt;isCommented){
      //start comment sequence
      //insert "&lt;!--"
    }
  
    writer.writeStartElement("BigStruct");
  
    for (int j = 0; j &lt; smallerStruct; j++){
        if (smallerStruct.at(i)-&gt;isCommented){
          //start comment sequence
          //insert "&lt;!--"
        }
  
        writer.writeStartElement("SmallerStruct");
  
        writer.writeTextElement("Stuff", "blah");
        writer.writeTextElement("More Stuff", "blah blah blah");
  
        writer.writeEndElement();
  
        if (smallerStruct.at(i)-&gt;isCommented){
          //end comment sequence
          //insert "--&gt;"
        }
    }
  
    writer.writeEndElement();
  
    if (bigStruct.at(i)-&gt;isCommented){
       //endcomment sequence
       //insert "--&gt;"
    }
  }
  
  ... 
  </code></pre>
  
  <p>An example XML output may look like </p>
  
  <pre><code>&lt;BigStruct&gt;
   &lt;SmallerStruct&gt;
      &lt;Stuff&gt;blah&lt;/Stuff&gt;
      &lt;More Stuff&gt;blah blah blah&lt;/More Stuff&gt;
   &lt;/SmallerStruct&gt;
   &lt;!--
    &lt;SmallerStruct&gt;
      &lt;Stuff&gt;blah&lt;/Stuff&gt;
      &lt;More Stuff&gt;blah blah blah&lt;/More Stuff&gt;
   &lt;/SmallerStruct&gt;
   --&gt;
  &lt;/BigStruct&gt;
  &lt;!--
  &lt;BigStruct&gt;
      &lt;SmallerStruct&gt;
      &lt;Stuff&gt;blah&lt;/Stuff&gt;
      &lt;More Stuff&gt;blah blah blah&lt;/More Stuff&gt;
   &lt;/SmallerStruct&gt;
  &lt;/BigStruct&gt;
  --&gt;
  </code></pre>
  
  <p>The writeComment() was my first attempt to comment, however, it only writes a single line. Of course, I could create a large string with '\n' characters where necessary, but the code necessary to create that block would escape the program flow of my loops. <strong>What I need is a slick way of essentially having a writer.startComment() and writer.endComment()</strong>... such that I can specify the start and end of a comment, after other xml has been written. Therefore I could write XML using my qxmlstreamwriter inside a comment. </p>
  
  <p>Thanks for your time.</p>