download-entities - download and parse XML Entity definitions
$ perl download-entities.pl -i # interactive $ perl download-entities.pl > output-file.pm $ perl download-entities.pl output-file.pm # instead of http://www.w3.org/2003/entities/iso9573-2003/ $ perl download-entities.pl http://my.server.com/entities.html
This script downloads the definitions of XML entities from http://www.w3.org/2003/entities/iso9573-2003/ or from whatever address you give it as an argument. The argument should be an URL (that LWP::UserAgent::get can access) pointing to a document with (absolute or relative) references to files ending with the .ent suffix. These files are expected to be DTD's with lines like
.ent
<!ENTITY amp "&" >
The script parses these files and prints the perl module to the standard output. If you wish, you can give "file" as another argument to the script and it will then print it to "file". You can also specify the output file in the environment variable OUTPUT_FILE.
OUTPUT_FILE
The index and the output file are distinguished by the presence of "://" substring. If you want to use a locally stored index file (the one with the .ent references), you can access it by saying
perl download.pl file:///path/to/index.html
Note that the script currently distinguishes between relative and absolute paths by looking at whether the href contains a "://" substring. This can lead to crashes when the links look like href="/path/file.ent".
Also, the script assumes the links have exactly the format href="..." - with double quotes.
In case you run into problems downloading the documents, you can try to run the script with the -i or --interactive option. This will let you skip downloads or enter alternative URLs for individual documents.
-i
--interactive
The interactive mode is also triggered when the INTERACTIVE environment variable is set to a true value (in Perl sense).
INTERACTIVE
Beside the --interactive option, this script also accepts the --timeout option. It specifies the timeout for LWP::UserAgent in seconds when downloading. The same is controlled by the DOWNLOAD_TIMEOUT environment variable. The defaule (180s) timeout is used when not specified.
--timeout
DOWNLOAD_TIMEOUT
# 10 seconds timeout - croak on failure perl download-entities.pl --timeout 10 > XML/Entities/Data.pm # 5 seconds timeout - croak on failure DOWNLOAD_TIMEOUT=5 perl download-entities.pl > XML/Entities/Data.pm # 1 second timeout - ask on failure perl download-entities.pl --interactive --timeout 1 > XML/Entities/Data.pm
This script has dependencies that the XML::Entities module does not and are therefore not mentioned in the META.yml file. These are LWP::UserAgent, File::Basename and Fatal.
XML::Entities
LWP::UserAgent
File::Basename
Fatal
Copyright 2010 Jan Oldrich Kruza <sixtease@cpan.org>. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install XML::Entities, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XML::Entities
CPAN shell
perl -MCPAN -e shell install XML::Entities
For more information on module installation, please visit the detailed CPAN module installation guide.