Scroog1
Scroog1

Reputation: 3579

Perl XML:DOM::Parser NoExpand still expanding entities

I am using the XML::DOM::Parser library to read an XML file, do some minor adjustments and dump it back out again. There are some encoded entities in the file and I want to preserve them in their encoded form. I've tried using the NoExpand option for the parser but it still seems to expand entities. The following is a minimal example of the problem:

use XML::DOM;
my $parser = new XML::DOM::Parser(NoExpand => 1);
my $doc = $parser->parse('<?xml version="1.0" encoding="UTF-8"?><MyTest Content="&#13;"/>');
print $doc->toString;

The output is the following (note the entity has been expanded):

<?xml version="1.0" encoding="UTF-8"?><MyTest Content="^M"/>

I'm using ActiveState Perl 5.16.3.1603 with XML::DOM 1.44 and XML::Parser 2.41

Is there any way of getting NoExpand to not expand that I've missed?

Upvotes: 2

Views: 270

Answers (1)

Kurt Starsinic
Kurt Starsinic

Reputation: 56

This takes a bit of documentation diving. As you can see in the documentation for XML::DOM::Parser:

The XML::Parser NoExpand option is more or less supported

Reviewing the relevant documentation for XML::Parser

This has no effect if a default handler has not been registered, and it has no effect on the expansion of entity references inside attribute values.

So, if this feature in this parser is going to work for you at all, it's not going to work for attribute values. If it really matters to you:

  • Try a different XML parser
  • File a bug or a patch with Enno Derksen, the author of XML::Parser.

Upvotes: 1

Related Questions