Speeding up loading the XHTML DTD on Linux (Mandriva Cooker x86-32)
Shlomi Fish <[email protected]> Wed, 6 Apr 2011 10:03:53 +0300
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <[email protected]> |
Hi all,
I have the following code to parse XHTML files and find the lines inside the
TEXT nodes which contain an ASCII double quotes (<< " >> ). It works, but
fails upon encountering an " " entity.
However, with load_ext_dtd set to 1, it tries to load the DTD from the network
which takes a long time here. I'm trying to put the XHTML DTDs in
/etc/xml/catalog , but I don't know what's the best way to do it. I can see
the XHTML DTDs in several Mandriva Cooker packages, but none of them seems to
be definitive.
If anyone can shed any light on it, I would appreciate it.
Regards,
Shlomi Fish
[ CODE ]
#!/usr/bin/perl
use strict;
use warnings;
use XML::LibXML;
use XML::LibXML::Reader;
use XML::LibXML::XPathContext;
use Getopt::Long;
my $out_fn;
# Input the filename
foreach my $filename (@ARGV)
{
my $reader = XML::LibXML::Reader->new(
location => $filename, load_ext_dtd => 0, 'no_network' => 1
) or die "Cannot read '$filename'.";
while ($reader->read())
{
if ($reader->nodeType() == XML_TEXT_NODE)
{
my $data = $reader->value;
my @lines = split(/\n/, $data, -1);
foreach my $idx (0 .. $#lines)
{
my $line = $lines[$idx];
if ($line =~ m{"})
{
printf {*STDOUT} ("%s:%d:%s\n",
$filename, $reader->lineNumber()+$idx, $line
);
}
}
}
}
}
[ / CODE ]
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
UNIX Fortune Cookies - http://www.shlomifish.org/humour/fortunes/
In Soviet Russia, every time you kill a kitten, God masturbates.
-- http://linux.slashdot.org/comments.pl?sid=195378&cid=16009070
Please reply to list if it's a mailing list post - http://shlom.in/reply .
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs