Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3484886
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:50:28+00:00 2026-05-18T10:50:28+00:00

I am trying comment a multiline section of xml to an output file using

  • 0

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 “< ! – -” (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 “<” 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 "-->"
  }
}

... 

An example XML output 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>
-->

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. What I need is a slick way of essentially having a writer.startComment() and writer.endComment()… 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.

Thanks for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:50:28+00:00Added an answer on May 18, 2026 at 10:50 am

    I don’t think that’s possible, looking at the QXmlStreamWriter API. You could use another QXmlStreamWriter on a temporary QByteArray, and write the byte array’s content as comment to the original writer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to comment out a large piece of code in a program but
Trying to pull fields 'info' and 'date' from Comment table. Two Tables: Php <?php
I'm trying to design a comment system for my RoR blogging site, and I
I'm trying to fire an event when you log in to comment, but for
hi i am trying to make an application which can submit a comment to
I am trying to remove comments containing a specific Java doc comment Eg. I
I am trying to develop an extension that will work similar to the Comment
I'm trying to display something like this on posts/index.html.erb Post #1 Comment #1 for
I'm trying to implement tree-like comments for my django projects. Each comment can be
A comment on one of my answers has left me a little puzzled. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.