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.