Hi all,
I have a set of XML files where one will be referenced in another. For example A->B->C->D etc.
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>
[download]
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>
[download]
Now for the code i use to process these xml files,
This code expands the top level xml file,
use XML:
OM;
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);
[download]
This code is used to parse the expanded top.xml where i get the error,
$parser = new XML:
OM::Parser;
my $doc = $parser->parsefile("$output_file");
[download]
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 ?