in reply to XML::Twig and ENTITY declarations

Well, if you define component-entities and then you use general-entities, any software will have trouble figuring out where to get the value you want.

Then indeed you need to remove the doctype declaration, which is probably a bug in XML::Twig, I have to check some more.

Once that's done, you need to use the parse_param_ent option to get the value to be read. That option is undocumented because it's inherited directly from XML::Parser. I'll add the doc about it in XML::Twig.

Once that's done, your file looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE sect1 [ <!ENTITY % component-entities SYSTEM "component.ent"> %component-entities; ]> <component>Engine-&engine-version;</component>

and you can see how it's processed by doing this:

perl -MXML::Twig -e'XML::Twig->new( parse_param_ent => 1)->parsefile( "ent1.xml")->print'

Replies are listed 'Best First'.
Re^2: XML::Twig and ENTITY declarations
by carcassonne (Pilgrim) on Mar 21, 2009 at 15:00 UTC
    Hi, the code is actually more than this and I've made a mistake when cutting down an example. So no, I do define and use the same.

    Thanks for pointing out the use of parse_param_ent ! Now it works as it should, and access to ENTITY variables is easy. Yes, it ought to be found in the XML::Twig docs.

    I've noticed that seemingly it cannot be used along with keep_encoding. In my case, that's fine and I won't bother with using both.

    On the other hand, the actual DOCTYPE declaration is not handled at all. I have to remove it (eg. sed it out) from the XML files. That could be a normal thing to do in a way since it directs to an external network resource. I'm not a XML expert.

    The following:

    <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [ <!ENTITY % component-entities SYSTEM "components.ent"> %component-entities; ]>

    Yields the following error:

    cannot expand > - cannot load 'http://www.oasis-open.org/docbook/xml/4 +.5/docbookx.dtd' at /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thr +ead-multi/XML/Parser/Expat.pm line 469

    Whereas the following is all OK:

    <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE sect1 [ <!ENTITY % component-entities SYSTEM "components.ent"> %component-entities; ]>

    Thanks.