Re: XML::LibXML: How to tell parse_balanced_chunk what DTD to use?

Robin Berjon <[email protected]> Mon, 13 Sep 2010 12:42:14 +0200
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
On Sep 9, 2010, at 09:40 , Reuben Thomas wrote:
> I am reading balanced chunks with the following code:
> 
>        my $parser = XML::LibXML->new();
>        my $chunk = slurp($objpath);
>        my $chunk_node;
>        eval { $chunk_node = $parser->parse_balanced_chunk($chunk); };
> 
> It so happens that the XML I am trying to parse is XHTML. When it
> contains an XHTML entity reference, I naturally get an undefined
> entity error.
> 
> How do I tell the parser object the DTD I am using?

If there's a way of doing that, I'm not aware of it. One solution (well, hack) could be to use parse_chunk() instead. You'd have to call it three times:

  - first with the DOCTYPE you want followed by an arbitrary open tag;
  - second with the data you wish to parse
  - finally with a tag to close the opening one, and the terminate flag set to true.

Then you can go grab the children of your invented root element (and stuff them into a DocumentFragment if you want the same interface as parse_balanced_chunk).

I know, it's not lovely, but it ought to work :)

-- 
Robin Berjon - http://berjon.com/



_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs