Re: XML::LibXML search path for DTDs
Roger Pepitone <[email protected]> Sat, 22 Sep 2012 12:24:51 -0700 (PDT)
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <[email protected]> |
Catalogs seem to be what I want, but I they don't seem to have any effect.
From http://search.cpan.org/~shlomif/XML-LibXML-2.0004/lib/XML/LibXML/Parser.pod
libxml2 supports XML catalogs. Catalogs are used to map remote resources to their local copies. Using catalogs can speed up parsing processes if many external resources from remote addresses are loaded into the parsed documents (such as DTDs or XIncludes).
Note that libxml2 has a global pool of loaded catalogs, so if you apply the method load_catalog to one parser instance, all parser instances will start using the catalog (in addition to other previously loaded catalogs).
Note also that catalogs are not used when a custom external entity handler is specified. At the current state it is not possible to make use of both types of resolving systems at the same time.
load_catalog
$parser->load_catalog( $catalog_file );
Loads the XML catalog file $catalog_file.
That really glosses over things.
Is there a return value? If so, what does it mean?
What sort of values can $catalog_file take? (Are string containing filename, string containing xml, and file handle all acceptable?)
#my $OFH = IO::Scalar->new;
open my $OFH, ">obj/catalog.dtd";
print {$OFH} "<?xml version='1.0'?>xyzzy\n";
print {$OFH} "<xcatalog xmlns='urn:oasis:names:tc:entity:xmlns:xml:catalog'>\n";
foreach (qw/file1 file2 file3 file4/) {
print {$OFH} " <public publicId='-//$_.dtd//EN' uri='$ENV{SVNDIR}/dtd/$_.dtd' />\n";
print {$OFH} " <system systemId='-//$_.dtd//EN' uri='$ENV{SVNDIR}/dtd/$_.dtd' />\n";
}
print {$OFH} "</catalog>\n";
#print "LOAD: ", $parser->load_catalog ($OFH), "!\n";
close $OFH;
print "LOAD2: ", $parser->load_catalog ("obj/catalog.dtd"), "!\n";
The "xyzzy" and "xcatalog" are deliberate errors, but load_catalog isn't showing any kind of error.
________________________________
From: Nick Wellnhofer <[email protected]>
To: Roger Pepitone <[email protected]>
Cc: "[email protected]" <[email protected]>
Sent: Thursday, September 13, 2012 12:13 PM
Subject: Re: XML::LibXML search path for DTDs
On 13/09/2012 19:04, Roger Pepitone wrote:
> Let me rephrase: I can work out where the DTDs will be. I'm having
> trouble giving that path to LibXML.
> - I can't put a path to the DTD into the XML file, because it will
> differ for various users.
> - I can't put in a line like $parser->parse_file ($xml_location,
> dtd_search_path => [ $dtd_location ]);
> into my Perl code because, AFAICT, there is no 'dtd_search_path'
> option.
Maybe XML catalogs work for you:
https://metacpan.org/module/XML::LibXML::Parser#XML-CATALOGS
Alternatively, you could try to write your own input callbacks that load the DTDs from the correct location:
https://metacpan.org/module/XML::LibXML::InputCallback
Nick
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs