PDA

View Full Version : storing and reading XML with commented attributes



so Qt
30th November 2015, 17:37
Lets say I have an XML file like this:


<root Version="1.0">
<!-- elem1 comment-->
<elem1 value="foo"/>
<!-- elem2 comment-->
<elem2>
<!-- elem2a comment-->
<elem2a value="foo"/>
<!-- elem2b comment-->
<elem2b value="foo"/>
<!-- elem2c comment-->
<elem2c value="foo"/>
</elem2>
<!-- elem3 comment-->
<elem3 value="foo"/>
</root>

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.

Qiieha
30th November 2015, 21:37
I would use QDomComment. Look at the docs. It's quite simple.