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@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.engelm...@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>

<<attachment: viktor_engelmann.vcf>>

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to