Results 1 to 3 of 3

Thread: Multiline comment with QXmlStreamWriter

  1. #1
    Join Date
    Jun 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Multiline comment with QXmlStreamWriter

    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:

    Qt Code:
    1. ...
    2. QXmlStreamWriter writer(&myFile)
    3.  
    4. for (int i = 0; i < bigStruct.size(); i++){
    5.  
    6. if (bigStruct.at(i)->isCommented){
    7. //start comment sequence
    8. //insert "<!--"
    9. }
    10.  
    11. writer.writeStartElement("BigStruct");
    12.  
    13. for (int j = 0; j < smallerStruct; j++){
    14. if (smallerStruct.at(i)->isCommented){
    15. //start comment sequence
    16. //insert "<!--"
    17. }
    18.  
    19. writer.writeStartElement("SmallerStruct");
    20.  
    21. writer.writeTextElement("Stuff", "blah");
    22. writer.writeTextElement("More Stuff", "blah blah blah");
    23.  
    24. writer.writeEndElement();
    25.  
    26. if (smallerStruct.at(i)->isCommented){
    27. //end comment sequence
    28. //insert "-->"
    29. }
    30. }
    31.  
    32. writer.writeEndElement();
    33.  
    34. if (bigStruct.at(i)->isCommented){
    35. //endcomment sequence
    36. //insert "-->"
    37. }
    38. }
    39.  
    40. ...
    To copy to clipboard, switch view to plain text mode 

    An example XML may look like:
    Qt Code:
    1. <BigStruct>
    2. <SmallerStruct>
    3. <Stuff>blah</Stuff>
    4. <More Stuff>blah blah blah</More Stuff>
    5. </SmallerStruct>
    6. <!--
    7. <SmallerStruct>
    8. <Stuff>blah</Stuff>
    9. <More Stuff>blah blah blah</More Stuff>
    10. </SmallerStruct>
    11. -->
    12. </BigStruct>
    13. <!--
    14. <BigStruct>
    15. <SmallerStruct>
    16. <Stuff>blah</Stuff>
    17. <More Stuff>blah blah blah</More Stuff>
    18. </SmallerStruct>
    19. </BigStruct>
    20. -->
    To copy to clipboard, switch view to plain text mode 

    Thanks for your time.
    Last edited by QtWannabe; 24th November 2010 at 18:28.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Multiline comment with QXmlStreamWriter


  3. #3
    Join Date
    Jun 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Multiline comment with QXmlStreamWriter

    Thanks for your time and reply.

    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. Therefor I could write XML using my qxmlstreamwriter inside a comment.

Similar Threads

  1. QXmlStreamWriter UTF-16 Problem
    By 27Loco in forum Qt Programming
    Replies: 3
    Last Post: 7th July 2010, 13:04
  2. Readable Xml with QXmlStreamWriter
    By jano_alex_es in forum Newbie
    Replies: 8
    Last Post: 26th August 2009, 11:53
  3. Multiline QCombobox
    By tyrdal in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2009, 18:37
  4. Request for comment: Post event filter
    By wysota in forum Qt Programming
    Replies: 3
    Last Post: 7th March 2008, 21:55
  5. simple QString comment
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 13th July 2006, 13:29

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.