Given the below two files:
doc.xml
<!DOCTYPE TEST [
<!ENTITY % get_em SYSTEM "entities.ent" >
%get_em;
]>
<TEST>
<COMPANY_ID>&COMPANY_ID;</COMPANY_ID>
</TEST>
entities.ent
<!ENTITY COMPANY_ID "84500">
<!ENTITY SPN_FIRM_ID "5900">
<!ENTITY SPN_CUSTD_REL_ID "40001">
<!ENTITY CUSTD_FIRM_NBR "229">
<!ENTITY CUSTD_FIRM_ID "5901">
<!ENTITY MASTERACCOUNT "TAL">
I can successfully use xmllint
:
xmllint --loaddtd --noent --dropdtd doc.xml
<?xml version="1.0"?>
<TEST>
<COMPANY_ID>84500</COMPANY_ID>
</TEST>
How could I get this idea to work in Perl and XML::Simple?
$ perl -MData::Dumper -MXML::Simple -e 'print Dumper XMLin q{doc.xml}'
doc.xml:4: parser error : PEReference: %get_em; not found
%get_em;
^
doc.xml:9: parser error : Entity 'COMPANY_ID' not defined
<COMPANY_ID>&COMPANY_ID;</COMPANY_ID>
^
After some comments, I've tried with XML::LibXML::Simple
it does look a little better but the entity still does not get resolved
$ perl -MData::Dumper -MXML::LibXML::Simple -e 'print Dumper XMLin q{doc.xml}'
./doc.xml:9: parser error : Entity 'COMPANY_ID' not defined
<COMPANY_ID>&COMPANY_ID;</COMPANY_ID>
^
Hmm and the PEReference
of the above stands out .. what's PE
?
But more importantly, how can I get Perl with XML::Simple to read external DTD?
I tired XML::Simple::DTDReader
but I find this module very restrictive especially it states specifically that none of XML::Simple
's myriad of options are supported!
If I include the ENTITY declarations in the doc.xml
itself it DOES work .. so obviously XML::Simple
knows how to handle the DOCTYPE
only I would like to use external DTD with SYSTEM
, and that's where I'm stuck to get it to work.