Hi Monks

I'm trying to load from an XML or HTML file into Wx::RichTextCtrl.

I have 2 pieces of code:

  1. (see richtext_test.pl below) is the Perl file with Wx::RichTextHTMLHandler->LoadFile
  2. (see output.xml below) is the XML file I am trying to load (created by ->SaveFile)

The relevant piece of code is:

my $XML_handler = Wx::RichTextXMLHandler->new; $XML_handler->LoadFile ( my $XML_buffer, "output.xml"); $self->{rich_text_ctrl_1}->SetValue ( $XML_buffer );

Which creates a handler (no error), tries to load the file and crashes the Perl interpreter with no error message.

Whether I use this code, or the HTML equivalent, which does nothing, except not crash, and no error message. Either way $XML_buffer/$HTML_buffer remains resolutely empty.

What am I doing wrong?

All suggestions gratefully received.

Regards

Steve

Attachment 1 - richtext_test.pl

#!/usr/bin/perl -w -- use Wx 0.15 qw[:allclasses]; use strict; package MyFrame; use Wx qw[:everything]; use base qw(Wx::Frame); use base qw(Class::Accessor::Fast); use Wx qw(:richtextctrl :textctrl :font :sizer :color); __PACKAGE__->mk_accessors( qw(richtext stylesheet control) ); sub new { my( $self, $parent, $id, $title, $pos, $size, $style, $name ) = @_ +; $style = wxDEFAULT_FRAME_STYLE unless defined $style; $self = $self->SUPER::new( undef, wxID_ANY, "Rich Text Control", w +xDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, "" ); $self->SetTitle("Rich Text Control"); $self->{Ctl_Post_Exam_Videos_Sizer_2} = Wx::BoxSizer->new(wxVERTIC +AL); # Top-level left-hand sizer (contains media) $self->{rich_text_ctrl_1} = Wx::RichTextCtrl->new( $self, -1, '', +[-1, -1], [800, 600] ); $self->richtext( $self->{rich_text_ctrl_1} ); my $sizer = Wx::BoxSizer->new( wxHORIZONTAL ); $sizer->Add( $self->{rich_text_ctrl_1}, 1, wxGROW|wxALL, 5 ); $self->SetSizerAndFit( $sizer ); $self->control ( $self ); my $XML_handler = Wx::RichTextXMLHandler->new; $XML_handler->LoadFile ( my $XML_buffer, "output.xml"); $self->{rich_text_ctrl_1}->SetValue ( $XML_buffer ); $self->SetSizer ($self->{Ctl_Post_Exam_Videos_Sizer_2}); $self->Layout(); return $self; ###### Updated, sorry I missed this bit out. package main; unless(caller){ local *Wx::App::OnInit = sub{1}; my $app = Wx::App->new(); Wx::InitAllImageHandlers(); my $frame_1 = MyFrame->new(); $app->SetTopWindow($frame_1); $frame_1->Show(1); $app->MainLoop(); } }

Attachment 2 - output.xml

<?xml version="1.0" encoding="UTF-8"?> <richtext version="1.0.0.0" xmlns="http://www.wxwidgets.org"> <paragraphlayout textcolor="#000000" fontsize="8" fontstyle="90" fon +tweight="90" fontunderlined="0" fontface="MS Shell Dlg 2" alignment=" +1" parspacingafter="10" parspacingbefore="0" linespacing="10"> <paragraph> <text>Test </text> </paragraph> </paragraphlayout> </richtext>

In reply to Wx::RichTextXMLHandler->LoadFile fails to load file into buffer. by Steve_BZ

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.