So I'm trying to dynamically process an XML file using the Wx::Perl::TreeChecker package. I've taken the treechecker.pl demo included in the TreeChecker source download and modified it for my use. My code and XML sample is below.

content_tree.pl
use strict; use Wx qw(:everything); use Wx::Perl::Carp; use XML::Simple; package Content_App; use vars '@ISA'; @ISA = 'Wx::App'; sub OnInit { my $self = shift; my $frame = MyTreeChecker_Frame->new('Wx::Perl::TreeChecker', Wx:: +wxDefaultPosition(), [450,450]); $self -> SetTopWindow ($frame); $frame -> Show(1); 1; } package MyTreeChecker_Frame; use vars '@ISA'; @ISA = 'Wx::Frame'; use Wx qw(:sizer :misc wxOK wxICON_INFORMATION wxBITMAP_TYPE_ICO wxID_ +ANY); use Wx::Perl::TreeChecker; sub new { my $class = shift; my ($title, $pos, $size) = @_; my $self = $class->SUPER::new (undef, -1, $title, $pos, $size); $self -> SetIcon (Wx::Icon->new("Resources\\Graphics\\main.ico", w +xBITMAP_TYPE_ICO)); my $filemenu = new Wx::Menu; my $menubar = new Wx::MenuBar; $filemenu -> Append (1, 'E&xit'); $menubar -> Append ($filemenu, '&File'); $self -> SetMenuBar ($menubar); use Wx::Event 'EVT_MENU', 'EVT_BUTTON', 'EVT_RIGHT_UP', 'EVT_RIGHT +_DOWN', 'EVT_TREE_ITEM_RIGHT_CLICK'; EVT_MENU ($self, 1, \&OnQuit); EVT_MENU ($self, 2, \&OnToggleMultiple); EVT_MENU ($self, 3, \&OnToggleItems); EVT_MENU ($self, 4, \&OnToggleContainers); EVT_MENU ($self, 5, \&OnToggleSelectAll); my $panel = new Wx::Panel ($self); my $sizer = new Wx::BoxSizer (wxVERTICAL); $self -> {treechecker} = new Wx::Perl::TreeChecker ($panel, -1, wx +DefaultPosition, wxDefaultSize); $sizer -> Add ($self -> {treechecker}, 1, wxGROW); $panel -> SetSizer ($sizer); $self -> fill_treechecker(); EVT_RIGHT_DOWN ( $self->{treechecker} , \&RightClickMenu); $self->{treechecker}->items_only(1); $self->{treechecker} -> allow_multiple(0); Wx::Event::EVT_TREELIST_ITEM_EXPANDING($self, $self->{treechecker} +, \&OnItemExpanding); Wx::Event::EVT_TREELIST_ITEM_EXPANDED($self, $self->{treechecker}, + \&OnItemExpanded); #Wx::Log::SetActiveTarget (new Wx::LogTextCtrl ($self -> {textctrl +})); return $self; } sub fill_treechecker { my $self = shift; my $treechecker = $self -> {treechecker}; our %scapHash = (); my $xml = XML::Simple::XMLin("modified_options.xml", ForceArray => + 1); foreach my $stream (@{$xml->{contents}}) { for my $content_name (@{$stream->{content}}) { for my $profile (@{$content_name->{profiles}}) { for my $profile_name (@{$profile->{profile}}) { push @{$scapHash{"$content_name->{stream}->[0]"}}, + $profile_name; } } } } _populate_tree($treechecker, "", \%scapHash); } sub _populate_tree { my ($tree, $id, $data) = @_; my $root; #recursively build a tree control return unless $data && ref $data; if (ref($data) eq 'HASH') { foreach my $stream (sort keys %$data) { print "\n". $stream . "\n"; my $stream_id = $tree -> AddRoot($stream); #my $container = $tree -> AppendContainer($stream_id, $str +eam, td($stream)); _populate_tree($tree, $stream_id, $data->{$stream}); } } elsif (ref $data eq 'ARRAY') { foreach my $profile (@$data) { print "\t$profile\n"; $tree-> AppendItem ($id, $profile, td($profile)); } } #$tree -> Expand ($id); } sub td { return new Wx::TreeItemData(shift); } sub OnQuit { my ($self, $evt) = @_; $self -> Close (1); } sub OnToggleMultiple { my ($self, $evt) = @_; my $tree = $self -> {treechecker}; $tree -> UnselectAll(); $tree -> allow_multiple($evt->IsChecked); } sub OnToggleItems { my ($self, $evt) = @_; my $tree = $self -> {treechecker}; $tree -> UnselectAll(); $tree -> containers_only(0); $tree -> items_only(1); } sub OnToggleContainers { my ($self, $evt) = @_; my $tree = $self -> {treechecker}; $tree -> UnselectAll(); $tree -> items_only(0); $tree -> containers_only(1); } sub OnToggleSelectAll { my ($self, $evt) = @_; my $tree = $self -> {treechecker}; $tree -> UnselectAll(); $tree -> items_only(1); $tree -> containers_only(0); } sub RightClickMenu { my( $self, $event ) = @_; my $menu = Wx::Menu->new( "" ); $menu->Append(7, "Select All", sub {$self->{treechecker}->Unselec +tAll(); $self->{treechecker}->items_only(1);}); $menu->AppendSeparator(); $menu->Append(8, "Clear All", sub {$self->{treechecker}->Unselect +All(); $self->{treechecker}->items_only(1);} ); $self->PopupMenu( $menu , $event->GetX, $event->GetY); } sub OnItemExpanded { my ($self, $event) = @_; my $item = $event->GetItem; my $itemtext = $self->{treechecker}->GetItemText($item); print('Evt Item has expanded : %s', $itemtext); } sub OnItemExpanding { my ($self, $event) = @_; my $item = $event->GetItem; my $itemtext = $self->{treechecker}->GetItemText($item); print "\n $itemtext"; Wx::LogMessage('Evt Item is expanding : %s', $itemtext); } ###################################################################### +######## package main; my $sample = new Content_App; $sample -> MainLoop;
modified_options.xml
<?xml version="1.0" encoding="UTF-8"?> <options> <timeStamp>2017-03-30T10:07:38</timeStamp> <contents> <content> <stream>stream_1</stream> <profiles> <profile>no_profile_selected</profile> <profile>profile_1</profile> </profiles> </content> <content> <stream>stream_2</stream> <profiles> <profile>no_profile_selected</profile> <profile>profile_1</profile> </profiles> </content> <content> <stream>stream_3</stream> <profiles> <profile>profile_1</profile> <profile>profile_2</profile> <profile>profile_3</profile> <profile>profile_4</profile> <profile>profile_5</profile> </profiles> </content> <content> <stream>stream_4</stream> <selectedProfile>profile_1</selectedProfile> <profiles> <profile>profile_1</profile> <profile>profile_2</profile> <profile>profile_3</profile> <profile>profile_4</profile> <profile>profile_5</profile> </profiles> </content> <content> <stream>stream_5</stream> <profiles> <profile>profile_1</profile> <profile>profile_2</profile> <profile>profile_3</profile> <profile>profile_4</profile> <profile>profile_5</profile> </profiles> </content> <content> <stream>stream_6</stream> <profiles> <profile>profile_1</profile> <profile>profile_2</profile> <profile>profile_3</profile> <profile>profile_4</profile> <profile>profile_5</profile> </profiles> </content> <content> <stream>stream_7</stream> <profiles> <profile>profile_1</profile> <profile>profile_2</profile> <profile>profile_3</profile> <profile>profile_4</profile> <profile>profile_5</profile> </profiles> </content> </contents> </options>
The print statements in the _populate_tree function prints everything as expected but the Window only displays stream_1 and it's profiles. Is it possible to have multiple roots in a single tree? Am I missing something or do I need to treat each stream as a separate tree?

In reply to Wx::Perl::TreeChecker multiple root nodes by swamprich

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.