in reply to XML::LibXML expand_entities always expands entities

The entities that this option refers to are not character entities (like &#47;) but ones defined by <!ENTITY ...> declarations. See this page for more info.

Here's an example of how it works:

#!/usr/bin/perl use strict; use XML::LibXML; my $fh = *DATA; my $parser = XML::LibXML->new(); $parser->expand_entities($ARGV[0]); my $doc = $parser->parse_fh( $fh ); my $root = $doc->getDocumentElement; print $root->toString(1, 1), "\n"; __END__ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE author [ <!ELEMENT author (#PCDATA)> <!ENTITY js "Jo Smith"> ]> <author>&js;</author>
If called with a true argument, the output will be:
<author>Jo Smith</author>
and if called with a false argument, the output is:
<author>&js;</author>

Replies are listed 'Best First'.
Re^2: XML::LibXML expand_entities always expands entities
by shamu (Acolyte) on May 14, 2008 at 16:54 UTC
    How can I prevent standard entities (e.g. &#47;) from being decoded?
Re^2: XML::LibXML expand_entities always expands entities
by shamu (Acolyte) on May 14, 2008 at 16:54 UTC