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

  • SEARCH
  • Home
  • 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 create a nested comment system using PHP and MySQL. But I'm
I'm trying to automate file comment headers. I'm stuck trying to figure out how
I'm trying to insert/add a line 'COMMENT DUMMY' at the beginnig of a file
I am trying to implement a nested comment in D. nestingBlockComment : '/+' (options
I'm trying to comment/uncomment a block of code using the shortcut Ctrl+C and Ctrl+K,
i trying to write a comment in each PHP file, then the comment will
I am trying to implement a threaded comment system using php, and i found
I'm trying to find comment blocks in PHP source code using regular expressions in
I am trying to save a user comment to my ashx web handler using
I'm trying to make a comment section for my site. After a comment has

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.