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.)


In reply to XML::Twig problem by BenHopkins

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.