Hi,

I really don't have a clue what is going on. I have a very simple XML file (see below), and an even simpler template. When I try to run this through tpage template.html it barfs out with the following error:
bash-2.03$ tpage template.html undef error - junk after document element at line 18, column 0, byte 221: </section> </site> <site language="fr"> ^ <section name="section 1"> <intro> at /usr/local/lib/site_perl/i386-linux/XML/Parser.pm line 185
So here is the XML file (called test.xml):
<?xml version="1.0"?> <site language="en"> <section name="section 1"> <intro> My darling </intro> <maintext> I love you </maintext> </section> <section name="section 2"> <maintext> The Bla </maintext> </section> </site> <site language="fr"> <section name="section 1"> <intro> mon amour </intro> <maintext> Je t'aime </maintext> </section> <section name="section 2"> <maintext> bla </maintext> </section> </site>
and here is the template (called template.html):
[% USE xpath = XML.XPath(file => "./test.xml") %] [% FOREACH site = xpath.findnodes('site') %] <h1>[% site.getAttribute('language') %]</h1> [% FOREACH section = xpath.findnodes('site/section') %] <h2>[% section.getAttribute('name') %]</h2> [% maintext = section.findnodes('maintext') %] [% maintext.string_value %] [% END %] [% END %]
when I remove the "french" part of the XML page (everything after the first </site>), it works like it should

Anyone?
--HolyGrail

In reply to Template Toolkit && XPath plugin by holygrail

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.