Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

XML::Parser undefined entity error

by ichimunki (Priest)
on Aug 18, 2001 at 17:56 UTC ( #105914=perlquestion: print w/replies, xml ) Need Help??

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=""></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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://105914]
Approved by root
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2023-12-10 01:15 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (38 votes). Check out past polls.