[Interest] Display XML in tree view

Viktor Engelmann viktor.engelmann at qt.io
Wed Aug 3 16:53:24 CEST 2016


Keep in mind that XML files can have <![CDATA[ ... ]]> sections. Because of
these and also different encodings etc., it would be quite hard to (always
correctly) determine the tree-structure of an XML file on a purely textual
level without actually parsing it.

So Jasons suggestion seems to be the best approach to me.
Let the DOM Parser do all the hard work for you :-)

Regards

Viktor


On 03.08.2016 16:29, Murphy, Sean wrote:
>>> I'm assuming this solution already exists, but either my google-fu isn't
>> working today, or it doesn't: I'd like to display an XML in a tree view, much
>> like many XML editing software applications do. All I'm looking for is display
>> the raw XML in a read-only tree view, but have the nodes be hierarchical so
>> that while looking at the XML, I can collapse/expand nodes.
>>> I have to believe this is already out there, but I'm just not stumbling across
>> it...
>>
>> I don't think anything exists already. TreeViews sure, XML sure. Combining
>> the two though, no.  But I don't think it would be hard. Qt's model/view
>> system should make it trivial. The only decisions are:
>> 1. Stream Reader interface or classic DOM parsing (both supported by Qt)
>> 2. Arrange the data as columns or roles.
>>
>> Once you have your model and parsing, then you can use it in a QTreeView.
> Yeah, I wasn't able to find what I wanted exactly, but the DOM model example,
> http://doc.qt.io/qt-5/qtwidgets-itemviews-simpledommodel-example.html, was
> really close to what I wanted. I just changed it to having only one column and then
> modifying what was written out. The DOM structure was great for generating the
> tree relationships between nodes. 
>
> My only complaint is once it's in the DOM the raw XML tag is lost, which is all I 
> want to display. Again, correct me if I'm just missing something obvious, I'm 
> pretty new to DOM. But if the original XML tag was:
>   <widget class="QWidget" name="centralWidget">
> that's exactly what I'd want to display, just with the expand/collapse arrow next
> to it. I'm not trying to actually parse and understand the data in the XML, I just want
> to display the XML node structure in the UI. But it seems that DOM is a little too 
> aggressive for my needs when parsing, and breaks up that tag into:
>   QDomNode::nodeName() // which just returns "widget"
>   QDomNode::attributes() // returns a map of attributes that has to be parsed
>
> Obviously it wasn't too hard to build up a string that puts things back the way they
> were, but I was surprised that doesn't exist already. Or maybe I need to dig a little 
> more? I just stumbled across http://doc.qt.io/qt-5/qdomnode.html#save which
> might do exactly what I need. Off to try to it now...
>
> Sean
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

-- 


Viktor Engelmann
Software Engineer

The Qt Company GmbH
Rudower Chaussee 13
D-12489 Berlin
Viktor.Engelmann at qt.io
+49
http://qt.io

Geschäftsführer: Mika Pälsi, Juha Varelius, Mika Harjuaho
Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht
Charlottenburg, HRB 144331 B
<http://qt.io>
<http://www.facebook.com/Qt> 	<http://www.twitter.com/qtproject>
<https://www.linkedin.com/company/the-qt-company/>
<https://plus.google.com/104580575722059274792>
<https://www.youtube.com/QtStudios>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160803/fec09515/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_logo_with_text_green_rgb_400x141.png
Type: image/png
Size: 16849 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160803/fec09515/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_facebook.png
Type: image/png
Size: 1407 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160803/fec09515/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_twitter.png
Type: image/png
Size: 1778 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160803/fec09515/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_linkedin.png
Type: image/png
Size: 1532 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160803/fec09515/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_googleplus.png
Type: image/png
Size: 1957 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160803/fec09515/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qt_youtube.png
Type: image/png
Size: 1610 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160803/fec09515/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: viktor_engelmann.vcf
Type: text/x-vcard
Size: 245 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160803/fec09515/attachment.vcf>


More information about the Interest mailing list