http://www.perlmonks.org?node_id=105914

ichimunki has asked for the wisdom of the Perl Monks concerning the following question:

I have XML like so:
<rec name="basic_header" type="template"> <title><pic path="logo"/>&nbsp;<link url="http://www.domain.com/"> +www.domain.com</link></title> <break type="line"/> </rec>

I have an XML::Parse constructor like so:
my $parser = XML::Parser->new( 'Handlers' => { Start => $xml_start, End => $xml_end, Char => $xml_char, Default => $xml_char, }, 'NoExpand' => 'TRUE', ); $parser->parse( $XML );
Where the handlers $xml_start, $xml_end, $xml_char are all anon sub refs-- the routines (for the most part) convert my XML to HTML for output. I've added the NoExpand option since this error, "undefined entity", started appearing. I've also tried point Unparsed and Entity handlers at $xml_char as well. Nothing helps... the error continues to appear. I suppose I could go to the trouble of creating an official DTD for my XML, but the list of entities is HUGE (since they will all be basically lifted from HTML)-- or are there a lot of entities I shouldn't have to define? Either way, how can I retain the entity in the text so that I can pass it along in my output?

Replies are listed 'Best First'.
Re: XML::Parser undefined entity error
by mirod (Canon) on Aug 18, 2001 at 18:19 UTC

    What you can do is use a "fake" DTD:

    <?xml version="1.0"?> <!DOCTYPE rec SYSTEM "dummy.dtd" []> <rec>...

    This will get rid of the errors, and you will get the entity in the Default handler. Make sure you reset properly what you buffer in that handler and you should be all set.