Hi Monks,
I have a set of XML files where one will be referenced in another. For example A->B->C->D etc....(Please refere to http://www.perlmonks.com/?node_id=817466 for my earlier query)

The intent of the script is to take information from all of these XMLs and then work on that data.

The script worked fine in perl version 5.8.8 but was giving a peculiar error when run in perl-5.8.9

The error is "xml declaration not at start of external entity at line 37, column 11, byte 1307 at /home/tools/perl-5.12.1/Linux-64bit/lib/site_perl/5.12.1/x86_64-linux/XML /Parser.pm line 187"

The error seems to be coming because of the first line in each of the XMLs, which is <?xml version="1.0" encoding="ISO-8859-1"?>, which I learned provides information regarding the type of encoding used.

So where am I going wrong ??

Thanks for your help

Regards,
joe

sample top level xml file:


<?xml version="1.0" encoding="ISO-8859-1"?> <top xmlns:xi="http://www.w3.org/2001/XInclude"> <module name="TOP"> <moduleref name="module_a"/> <moduleref name="module_b"/> <moduleref name="module_c"/> <data>data</data> <data>data</data> </module> <xi:include href="$WORK_ROOT/MOD_A/module_a.xml"/> <xi:include href="$WORK_ROOT/MOD_B/module_b.xml"/> <xi:include href="$WORK_ROOT/MOD_C/module_c.xml"/> </top>


sample module xml


<?xml version="1.0" encoding="ISO-8859-1"?> <record xmlns:xi="http://www.w3.org/2001/XInclude"> <module type="record" name="module_a"> <data>data</data> <data>data</data> </module> </record>


Now for the code i use to process these xml files,

This code expands the top level xml file,


use XML::DOM; use XML::SAX; use XML::SAX::Writer; use FindBin; use lib "$FindBin::Bin"; use PATHREF; use IO::File; use File::Find; use File::Copy; use Cwd; use strict; my $input_file = "top.xml"; my $output_file = "output.xml"; my $output = new IO::File ">$output_file"; print "Expanding include tags...\n"; my $parser = XML::SAX::ParserFactory->parser( Handler =>XML::Filter::XInclude->new( Handler => XML::SAX::Writer->new(Output=>$output) ) ); $parser->parse_uri($input_file); close($output);


This code is used to parse the expanded top.xml where i get the error,


$parser = new XML::DOM::Parser; my $doc = $parser->parsefile("$output_file");


Note : 1.the module PATHREF is actually the module XML::Filter::XInclude modified to process ENV variable $WORK_ROOT
2.also i ran the script both in 5.8.9 and 5.12.1 but still the same error



PS: This info might help,
i tried removing the content <?xml version="1.0" encoding="ISO-8859-1"?> from the expanded top.xml and there were no errors!!! so does that mean i need not give this info in each of the XMLs or do i have to remove this after expansion everytime to avoid the error ?


In reply to XML parser error by joeperl

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.