I have a little program based on the twig's doc "Building An XML Filter." It makes roots for the things I need to process, and uses twig_print_outside_roots.
However, the output is NOT valid xml (the input is). Here's how the input starts:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE nitf SYSTEM "../CCI-DTD/nitf-3-1.dtd" [
<!ENTITY % HTMLlat1 PUBLIC "-//W3C//ENTITIES Latin 1 for X
+HTML//EN" "../CCI-DTD/xhtml-lat1.ent">
%HTMLlat1;
<!ENTITY % HTMLsymbol PUBLIC "-//W3C//ENTITIES Symbols for
+ XHTML//EN" "../CCI-DTD/xhtml-symbol.ent">
%HTMLsymbol;
<!ENTITY % HTMLspecial PUBLIC "-//W3C//ENTITIES Special fo
+r XHTML//EN" "../CCI-DTD/xhtml-special.ent">
%HTMLspecial;
]>
Here's the output:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE nitf SYSTEM "../CCI-DTD/nitf-3-1.dtd">
<!ENTITY % HTMLlat1 PUBLIC "-//W3C//ENTITIES Latin 1 for X
+HTML//EN" "../CCI-DTD/xhtml-lat1.ent">
%HTMLlat1;
<!ENTITY % HTMLsymbol PUBLIC "-//W3C//ENTITIES Symbols for
+ XHTML//EN" "../CCI-DTD/xhtml-symbol.ent">
%HTMLsymbol;
<!ENTITY % HTMLspecial PUBLIC "-//W3C//ENTITIES Special fo
+r XHTML//EN" "../CCI-DTD/xhtml-special.ent">
%HTMLspecial;
>
The square brackets surrounding the three !ENTITY declarations are missing. Here's the program's new declaration:
my $t = XML::Twig->new(
twig_roots => { "$nitf_root/body/body.head/hedline/hl1" => \&f
+ix_hl1,
"$nitf_root/body/body.head/hedline/hl2" => \&f
+ix_hl2,
},
twig_print_outside_roots => 1,
keep_encoding => 1,
);
At first I didn't have keep_encoding, and then besides the missing square brackets, the first !ENTITY was also missing. keep_encoding restored the first !ENTITY, but not the brackets.
Any ideas?
(I do a flush after the parse, so it's not that, althought I don't see how it could affect anything, I saw something about it.)