Results 1 to 2 of 2

Thread: storing and reading XML with commented attributes

  1. #1
    Join Date
    May 2015
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default storing and reading XML with commented attributes

    Lets say I have an XML file like this:

    Qt Code:
    1. [B]<root Version="1.0">[/B]
    2. <!-- elem1 comment-->
    3. [B]<elem1 value="foo"/>[/B]
    4. <!-- elem2 comment-->
    5. [B]<elem2>[/B]
    6. <!-- elem2a comment-->
    7. [B]<elem2a value="foo"/>[/B]
    8. <!-- elem2b comment-->
    9. [B]<elem2b value="foo"/>[/B]
    10. <!-- elem2c comment-->
    11. [B]<elem2c value="foo"/>[/B]
    12. [B]</elem2>[/B]
    13. <!-- elem3 comment-->
    14. [B]<elem3 value="foo"/>
    15. </root>[/B]
    To copy to clipboard, switch view to plain text mode 

    Is it possible to read this, represent it in my program, potentially modify it and write the updated structure back to disk without losing the comment <-> element connection? It's not a problem if comment must be subelements of or sth. similar, I just wanna have a consistent way of commenting elements.

  2. #2
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: storing and reading XML with commented attributes

    I would use QDomComment. Look at the docs. It's quite simple.

Similar Threads

  1. Data Reading and Storing in arrays
    By kango in forum Newbie
    Replies: 8
    Last Post: 6th January 2013, 16:13
  2. Replies: 1
    Last Post: 31st July 2012, 10:57
  3. Storing and reading back template types in QVariant
    By Daniel Dekkers in forum Qt Programming
    Replies: 1
    Last Post: 5th April 2010, 08:40
  4. Replies: 0
    Last Post: 9th March 2010, 14:02
  5. Storing/Reading item creation date
    By maverick_pol in forum Qt Programming
    Replies: 2
    Last Post: 26th May 2008, 09:19

Tags for this Thread

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.