Revision history for Perl extension XML::LibXML
+2.0202 2020-01-13
+ - Disable loading external DTDs or external entities by default
+ - Thanks to Tim Retout
+ - Docs: Noting that HTTPS doesn't work for schema-loading either.
+ - Thanks to Jason McIntosh
+ - Allow to parse RelaxNG without accessing network
+ - Thanks to PALI
+ - Allow to parse XML Schema without accessing network
+ - Thanks to PALI
+ - Add Test-Count assertion count checking using
+ https://metacpan.org/pod/Code::TidyAll::Plugin::TestCount
+
2.0201 2019-05-25
- Set MIN_PERL_VERSION to 5.8.1.
- Alien::Libxml2 Makefile.PL cleanups.
use IO::Handle; # for FH reads called as methods
BEGIN {
-$VERSION = "2.0201"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0202"; # VERSION TEMPLATE: DO NOT CHANGE
$ABI_VERSION = 2;
require Exporter;
require DynaLoader;
HTML_PARSE_NOERROR => (1<<5), # suppress error reports
};
-$XML_LIBXML_PARSE_DEFAULTS = ( XML_PARSE_NODICT | XML_PARSE_DTDLOAD | XML_PARSE_NOENT );
+$XML_LIBXML_PARSE_DEFAULTS = ( XML_PARSE_NODICT );
# this hash is made global so that applications can add names for new
# libxml2 parser flags as temporary workaround
}
# parser flags
$opts{no_blanks} = !$opts{keep_blanks} if exists($opts{keep_blanks}) and !exists($opts{no_blanks});
+ $opts{load_ext_dtd} = $opts{expand_entities} if exists($opts{expand_entities}) and !exists($opts{load_ext_dtd});
for (keys %OUR_FLAGS) {
$self->{$OUR_FLAGS{$_}} = delete $opts{$_};
my $self = undef;
if ( defined $args{location} ) {
- $self = $class->parse_location( $args{location} );
+ $self = $class->parse_location( $args{location}, XML::LibXML->_parser_options(\%args), $args{recover} );
}
elsif ( defined $args{string} ) {
- $self = $class->parse_buffer( $args{string} );
+ $self = $class->parse_buffer( $args{string}, XML::LibXML->_parser_options(\%args), $args{recover} );
}
elsif ( defined $args{DOM} ) {
- $self = $class->parse_document( $args{DOM} );
+ $self = $class->parse_document( $args{DOM}, XML::LibXML->_parser_options(\%args), $args{recover} );
}
return $self;
my $self = undef;
if ( defined $args{location} ) {
- $self = $class->parse_location( $args{location} );
+ $self = $class->parse_location( $args{location}, XML::LibXML->_parser_options(\%args), $args{recover} );
}
elsif ( defined $args{string} ) {
- $self = $class->parse_buffer( $args{string} );
+ $self = $class->parse_buffer( $args{string}, XML::LibXML->_parser_options(\%args), $args{recover} );
}
return $self;
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
xmlRelaxNGPtr
-parse_location( self, url )
+parse_location( self, url, parser_options = 0, recover = FALSE )
char * url
+ int parser_options
+ bool recover
PREINIT:
const char * CLASS = "XML::LibXML::RelaxNG";
xmlRelaxNGParserCtxtPtr rngctxt = NULL;
+ xmlExternalEntityLoader old_ext_ent_loader = NULL;
PREINIT_SAVED_ERROR
CODE:
INIT_ERROR_HANDLER;
(xmlRelaxNGValidityWarningFunc)LibXML_error_handler_ctx,
saved_error );
#endif
+
+ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) {
+ old_ext_ent_loader = xmlGetExternalEntityLoader();
+ xmlSetExternalEntityLoader( xmlNoNetExternalEntityLoader );
+ }
+
RETVAL = xmlRelaxNGParse( rngctxt );
+
+ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) )
+ xmlSetExternalEntityLoader( (xmlExternalEntityLoader)old_ext_ent_loader );
+
xmlRelaxNGFreeParserCtxt( rngctxt );
CLEANUP_ERROR_HANDLER;
- REPORT_ERROR((RETVAL == NULL) ? 0 : 1);
+ REPORT_ERROR((RETVAL == NULL) ? 0 : recover);
OUTPUT:
RETVAL
xmlRelaxNGPtr
-parse_buffer( self, perlstring )
+parse_buffer( self, perlstring, parser_options = 0, recover = FALSE )
SV * perlstring
+ int parser_options
+ bool recover
PREINIT:
const char * CLASS = "XML::LibXML::RelaxNG";
xmlRelaxNGParserCtxtPtr rngctxt = NULL;
+ xmlExternalEntityLoader old_ext_ent_loader = NULL;
char * string = NULL;
STRLEN len = 0;
PREINIT_SAVED_ERROR
(xmlRelaxNGValidityWarningFunc)LibXML_error_handler_ctx,
saved_error );
#endif
+
+ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) {
+ old_ext_ent_loader = xmlGetExternalEntityLoader();
+ xmlSetExternalEntityLoader( xmlNoNetExternalEntityLoader );
+ }
+
RETVAL = xmlRelaxNGParse( rngctxt );
+
+ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) )
+ xmlSetExternalEntityLoader( (xmlExternalEntityLoader)old_ext_ent_loader );
+
xmlRelaxNGFreeParserCtxt( rngctxt );
CLEANUP_ERROR_HANDLER;
- REPORT_ERROR((RETVAL == NULL) ? 0 : 1);
+ REPORT_ERROR((RETVAL == NULL) ? 0 : recover);
OUTPUT:
RETVAL
xmlRelaxNGPtr
-parse_document( self, doc )
+parse_document( self, doc, parser_options = 0, recover = FALSE )
xmlDocPtr doc
+ int parser_options
+ bool recover
PREINIT:
const char * CLASS = "XML::LibXML::RelaxNG";
xmlRelaxNGParserCtxtPtr rngctxt = NULL;
+ xmlExternalEntityLoader old_ext_ent_loader = NULL;
PREINIT_SAVED_ERROR
CODE:
INIT_ERROR_HANDLER;
(xmlRelaxNGValidityWarningFunc)LibXML_error_handler_ctx,
saved_error );
#endif
+
+ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) {
+ old_ext_ent_loader = xmlGetExternalEntityLoader();
+ xmlSetExternalEntityLoader( xmlNoNetExternalEntityLoader );
+ }
+
RETVAL = xmlRelaxNGParse( rngctxt );
+
+ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) )
+ xmlSetExternalEntityLoader( (xmlExternalEntityLoader)old_ext_ent_loader );
+
xmlRelaxNGFreeParserCtxt( rngctxt );
CLEANUP_ERROR_HANDLER;
- REPORT_ERROR((RETVAL == NULL) ? 0 : 1);
+ REPORT_ERROR((RETVAL == NULL) ? 0 : recover);
OUTPUT:
RETVAL
xmlSchemaPtr
-parse_location( self, url )
+parse_location( self, url, parser_options = 0, recover = FALSE )
char * url
+ int parser_options
+ bool recover
PREINIT:
const char * CLASS = "XML::LibXML::Schema";
xmlSchemaParserCtxtPtr rngctxt = NULL;
+ xmlExternalEntityLoader old_ext_ent_loader = NULL;
PREINIT_SAVED_ERROR
CODE:
INIT_ERROR_HANDLER;
(xmlSchemaValidityWarningFunc)LibXML_error_handler_ctx,
saved_error );
+ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) {
+ old_ext_ent_loader = xmlGetExternalEntityLoader();
+ xmlSetExternalEntityLoader( xmlNoNetExternalEntityLoader );
+ }
+
RETVAL = xmlSchemaParse( rngctxt );
+
+ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) )
+ xmlSetExternalEntityLoader( (xmlExternalEntityLoader)old_ext_ent_loader );
+
xmlSchemaFreeParserCtxt( rngctxt );
CLEANUP_ERROR_HANDLER;
- REPORT_ERROR((RETVAL == NULL) ? 0 : 1);
+ REPORT_ERROR((RETVAL == NULL) ? 0 : recover);
OUTPUT:
RETVAL
xmlSchemaPtr
-parse_buffer( self, perlstring )
+parse_buffer( self, perlstring, parser_options = 0, recover = FALSE )
SV * perlstring
+ int parser_options
+ bool recover
PREINIT:
const char * CLASS = "XML::LibXML::Schema";
xmlSchemaParserCtxtPtr rngctxt = NULL;
+ xmlExternalEntityLoader old_ext_ent_loader = NULL;
char * string = NULL;
STRLEN len = 0;
PREINIT_SAVED_ERROR
(xmlSchemaValidityWarningFunc)LibXML_error_handler_ctx,
saved_error );
+ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) ) {
+ old_ext_ent_loader = xmlGetExternalEntityLoader();
+ xmlSetExternalEntityLoader( xmlNoNetExternalEntityLoader );
+ }
+
RETVAL = xmlSchemaParse( rngctxt );
+
+ if ( EXTERNAL_ENTITY_LOADER_FUNC == NULL && (parser_options & XML_PARSE_NONET) )
+ xmlSetExternalEntityLoader( (xmlExternalEntityLoader)old_ext_ent_loader );
+
xmlSchemaFreeParserCtxt( rngctxt );
CLEANUP_ERROR_HANDLER;
- REPORT_ERROR((RETVAL == NULL) ? 0 : 1);
+ REPORT_ERROR((RETVAL == NULL) ? 0 : recover);
OUTPUT:
RETVAL
test/relaxng/demo3.rng
test/relaxng/demo4.rng
test/relaxng/invaliddemo.xml
+test/relaxng/net.rng
test/relaxng/schema.rng
test/schema/badschema.xsd
test/schema/demo.xml
test/schema/invaliddemo.xml
+test/schema/net.xsd
test/schema/schema.xsd
test/textReader/countries.xml
test/xinclude/entity.txt
"web" : "https://github.com/shlomif/perl-XML-LibXML"
}
},
- "version" : "2.0201",
- "x_serialization_backend" : "JSON::PP version 2.97001"
+ "version" : "2.0202",
+ "x_serialization_backend" : "JSON::PP version 4.02"
}
warnings: '0'
resources:
repository: https://github.com/shlomif/perl-XML-LibXML.git
-version: '2.0201'
+version: '2.0202'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
</authorgroup>
- <edition>2.0201</edition>
+ <edition>2.0202</edition>
<copyright>
<year>2001-2007</year>
<holder>AxKit.com Ltd</holder>
</funcsynopsisinfo>
</funcsynopsis>
<para>This function is available since XML::LibXML 1.70. It provides easy to use interface to the XML parser that parses
- given file (or URL), string, or input stream
+ given file (or non-HTTPS URL), string, or input stream
to a DOM tree. The arguments
can be passed in a HASH reference
or as name => value pairs.
and <xref linkend="parser-options"/>
for more information.
</para>
+ <para>Note that, due to a limitation in the underlying libxml2
+ library, this call does not recognize HTTPS-based URLs. (It
+ will treat an HTTPS URL as a filename, likely throwing a "No such
+ file or directory" exception.)
+ </para>
</listitem>
</varlistentry>
<varlistentry>
</funcsynopsis>
<para>This function parses an XML document from a file or network;
- $xmlfilename can be either a filename or an URL.
+ $xmlfilename can be either a filename or a (non-HTTPS) URL.
Note that for parsing files, this function is the fastest choice,
about 6-8 times faster then parse_fh().
</para>
+
</listitem>
</varlistentry>
</funcsynopsis>
<para>Similar to parse_file() but parses HTML (strict) documents;
- $htmlfile can be filename or URL.
+ $htmlfile can be filename or (non-HTTPS) URL.
</para>
<para>An optional second argument can be
used to pass some options to the HTML
</funcsynopsis>
<para>This will unbind the Child Node from its parent <function>$node</function>. The function returns the unbound node. If
- <function>oldNode</function> is not a child of the given Node the function will fail.</para>
+ <function>$childnode</function> is not a child of the given Node the function will fail.</para>
</listitem>
</varlistentry>
<listitem>
<funcsynopsis>
- <funcsynopsisinfo>$rngschema = XML::LibXML::RelaxNG->new( location => $filename_or_url );
-$rngschema = XML::LibXML::RelaxNG->new( string => $xmlschemastring );
-$rngschema = XML::LibXML::RelaxNG->new( DOM => $doc );</funcsynopsisinfo>
+ <funcsynopsisinfo>$rngschema = XML::LibXML::RelaxNG->new( location => $filename_or_url, no_network => 1 );
+$rngschema = XML::LibXML::RelaxNG->new( string => $xmlschemastring, no_network => 1 );
+$rngschema = XML::LibXML::RelaxNG->new( DOM => $doc, no_network => 1 );</funcsynopsisinfo>
</funcsynopsis>
- <para>The constructor of XML::LibXML::RelaxNG may get called with either one of three parameters. The parameter tells the class from which
- source it should generate a validation schema. It is important, that each schema only have a single source.</para>
+ <para>The constructor of XML::LibXML::RelaxNG needs to be called with list of parameters. At least location, string or DOM parameter is required to
+ specify source of schema. Optional parameter no_network set to 1 cause that parser would not access network and optional parameter recover
+ set 1 cause that parser would not call die() on errors.</para>
+
+ <para>It is important, that each schema only have a single source.</para>
<para>The location parameter allows one to parse a schema
- from the filesystem or a URL.</para>
+ from the filesystem or a (non-HTTPS) URL.</para>
<para>The string parameter will parse the schema from the given XML string.</para>
<listitem>
<funcsynopsis>
- <funcsynopsisinfo>$xmlschema = XML::LibXML::Schema->new( location => $filename_or_url );
-$xmlschema = XML::LibXML::Schema->new( string => $xmlschemastring );</funcsynopsisinfo>
+ <funcsynopsisinfo>$xmlschema = XML::LibXML::Schema->new( location => $filename_or_url, no_network => 1 );
+$xmlschema = XML::LibXML::Schema->new( string => $xmlschemastring, no_network => 1 );</funcsynopsisinfo>
</funcsynopsis>
- <para>The constructor of XML::LibXML::Schema may get called with either one of two parameters. The parameter tells the class from which
- source it should generate a validation schema. It is important, that each schema only have a single source.</para>
+ <para>The constructor of XML::LibXML::Schema needs to be called with list of parameters. At least location or string parameter is required to
+ specify source of schema. Optional parameter no_network set to 1 cause that parser would not access network and optional parameter recover
+ set 1 cause that parser would not call die() on errors.</para>
+
+ <para>It is important, that each schema only have a single source.</para>
<para>The location parameter allows one to parse a schema
- from the filesystem or a URL.</para>
+ from the filesystem or a (non-HTTPS) URL.</para>
<para>The string parameter will parse the schema from the given XML string.</para>
<varlistentry>
<term>location</term>
<listitem>
- <para>Read XML from a local file or URL.</para>
+ <para>Read XML from a local file or (non-HTTPS) URL.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>RelaxNG => $rng_schema</term>
<listitem>
<para>can be used to pass either a <xref linkend="XML-LibXML-RelaxNG"/>
- object or a filename or URL of a RelaxNG schema to the
+ object or a filename or (non-HTTPS) URL of a RelaxNG schema to the
constructor. The schema is then used to validate the
document as it is processed.</para>
</listitem>
<term>Schema => $xsd_schema</term>
<listitem>
<para>can be used to pass either a <xref linkend="XML-LibXML-Schema"/>
- object or a filename or URL of a W3C XSD schema to the
+ object or a filename or (non-HTTPS) URL of a W3C XSD schema to the
constructor. The schema is then used to validate the
document as it is processed.</para>
</listitem>
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
our @ISA = qw/Tie::Hash/;
use vars qw($VERSION);
-$VERSION = "2.0201"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0202"; # VERSION TEMPLATE: DO NOT CHANGE
BEGIN
{
use vars qw ($VERSION);
-$VERSION = "2.0201"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0202"; # VERSION TEMPLATE: DO NOT CHANGE
use overload
'""' => \&value,
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
@ISA = qw(Exporter);
-$VERSION = "2.0201"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0202"; # VERSION TEMPLATE: DO NOT CHANGE
use XML::LibXML qw(:libxml);
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
use XML::LibXML;
use vars qw ($VERSION);
-$VERSION = "2.0201"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0202"; # VERSION TEMPLATE: DO NOT CHANGE
use 5.008_000;
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
use warnings;
use vars qw($VERSION);
-$VERSION = "2.0201"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0202"; # VERSION TEMPLATE: DO NOT CHANGE
use constant ERR_OK => 0;
use constant ERR_INTERNAL_ERROR => 1;
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
fallback => 1;
$WARNINGS = 0; # 0: suppress, 1: report via warn, 2: report via die
-$VERSION = "2.0201"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0202"; # VERSION TEMPLATE: DO NOT CHANGE
use constant XML_ERR_NONE => 0;
use constant XML_ERR_WARNING => 1; # A simple warning
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
use warnings;
use vars qw ($VERSION);
-$VERSION = "2.0201"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0202"; # VERSION TEMPLATE: DO NOT CHANGE
use overload
'""' => \&value,
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
$childnode = $node->removeChild( $childnode );
-This will unbind the Child Node from its parent C<<<<<< $node >>>>>>. The function returns the unbound node. If C<<<<<< oldNode >>>>>> is not a child of the given Node the function will fail.
+This will unbind the Child Node from its parent C<<<<<< $node >>>>>>. The function returns the unbound node. If C<<<<<< $childnode >>>>>> is not a child of the given Node the function will fail.
=item replaceChild
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
use XML::LibXML::Number;
use vars qw($VERSION);
-$VERSION = "2.0201"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0202"; # VERSION TEMPLATE: DO NOT CHANGE
use overload
'""' => \&to_literal,
use warnings;
use vars qw ($VERSION);
-$VERSION = "2.0201"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0202"; # VERSION TEMPLATE: DO NOT CHANGE
use overload
'""' => \&value,
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
This function is available since XML::LibXML 1.70. It provides easy to use
-interface to the XML parser that parses given file (or URL), string, or input
-stream to a DOM tree. The arguments can be passed in a HASH reference or as
-name => value pairs. The function can be called as a class method or an object
-method. In both cases it internally creates a new parser instance passing the
-specified parser options; if called as an object method, it clones the original
-parser (preserving its settings) and additionally applies the specified options
-to the new parser. See the constructor C<<<<<< new >>>>>> and L<<<<<< Parser Options >>>>>> for more information.
+interface to the XML parser that parses given file (or non-HTTPS URL), string,
+or input stream to a DOM tree. The arguments can be passed in a HASH reference
+or as name => value pairs. The function can be called as a class method or an
+object method. In both cases it internally creates a new parser instance
+passing the specified parser options; if called as an object method, it clones
+the original parser (preserving its settings) and additionally applies the
+specified options to the new parser. See the constructor C<<<<<< new >>>>>> and L<<<<<< Parser Options >>>>>> for more information.
+
+Note that, due to a limitation in the underlying libxml2 library, this call
+does not recognize HTTPS-based URLs. (It will treat an HTTPS URL as a filename,
+likely throwing a "No such file or directory" exception.)
=item load_html
$doc = $parser->parse_file( $xmlfilename );
This function parses an XML document from a file or network; $xmlfilename can
-be either a filename or an URL. Note that for parsing files, this function is
-the fastest choice, about 6-8 times faster then parse_fh().
+be either a filename or a (non-HTTPS) URL. Note that for parsing files, this
+function is the fastest choice, about 6-8 times faster then parse_fh().
=item parse_fh
$doc = $parser->parse_html_file( $htmlfile, \%opts );
Similar to parse_file() but parses HTML (strict) documents; $htmlfile can be
-filename or URL.
+filename or (non-HTTPS) URL.
An optional second argument can be used to pass some options to the HTML parser
as a HASH reference. See options labeled with HTML in L<<<<<< Parser Options >>>>>>.
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
use warnings;
use vars qw ($VERSION);
-$VERSION = "2.0201"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0202"; # VERSION TEMPLATE: DO NOT CHANGE
use 5.008_000;
=item location
-Read XML from a local file or URL.
+Read XML from a local file or (non-HTTPS) URL.
=item string
=item RelaxNG => $rng_schema
-can be used to pass either a L<<<<<< XML::LibXML::RelaxNG >>>>>> object or a filename or URL of a RelaxNG schema to the constructor. The schema
-is then used to validate the document as it is processed.
+can be used to pass either a L<<<<<< XML::LibXML::RelaxNG >>>>>> object or a filename or (non-HTTPS) URL of a RelaxNG schema to the constructor.
+The schema is then used to validate the document as it is processed.
=item Schema => $xsd_schema
-can be used to pass either a L<<<<<< XML::LibXML::Schema >>>>>> object or a filename or URL of a W3C XSD schema to the constructor. The schema
-is then used to validate the document as it is processed.
+can be used to pass either a L<<<<<< XML::LibXML::Schema >>>>>> object or a filename or (non-HTTPS) URL of a W3C XSD schema to the constructor.
+The schema is then used to validate the document as it is processed.
=item ...
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
use XML::LibXML;
$doc = XML::LibXML->new->parse_file($url);
- $rngschema = XML::LibXML::RelaxNG->new( location => $filename_or_url );
- $rngschema = XML::LibXML::RelaxNG->new( string => $xmlschemastring );
- $rngschema = XML::LibXML::RelaxNG->new( DOM => $doc );
+ $rngschema = XML::LibXML::RelaxNG->new( location => $filename_or_url, no_network => 1 );
+ $rngschema = XML::LibXML::RelaxNG->new( string => $xmlschemastring, no_network => 1 );
+ $rngschema = XML::LibXML::RelaxNG->new( DOM => $doc, no_network => 1 );
eval { $rngschema->validate( $doc ); };
=head1 DESCRIPTION
=item new
- $rngschema = XML::LibXML::RelaxNG->new( location => $filename_or_url );
- $rngschema = XML::LibXML::RelaxNG->new( string => $xmlschemastring );
- $rngschema = XML::LibXML::RelaxNG->new( DOM => $doc );
+ $rngschema = XML::LibXML::RelaxNG->new( location => $filename_or_url, no_network => 1 );
+ $rngschema = XML::LibXML::RelaxNG->new( string => $xmlschemastring, no_network => 1 );
+ $rngschema = XML::LibXML::RelaxNG->new( DOM => $doc, no_network => 1 );
-The constructor of XML::LibXML::RelaxNG may get called with either one of three
-parameters. The parameter tells the class from which source it should generate
-a validation schema. It is important, that each schema only have a single
-source.
+The constructor of XML::LibXML::RelaxNG needs to be called with list of
+parameters. At least location, string or DOM parameter is required to specify
+source of schema. Optional parameter no_network set to 1 cause that parser
+would not access network and optional parameter recover set 1 cause that parser
+would not call die() on errors.
+
+It is important, that each schema only have a single source.
The location parameter allows one to parse a schema from the filesystem or a
-URL.
+(non-HTTPS) URL.
The string parameter will parse the schema from the given XML string.
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
use vars qw($VERSION @ISA);
-$VERSION = "2.0201"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0202"; # VERSION TEMPLATE: DO NOT CHANGE
use XML::LibXML;
use XML::SAX::Base;
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
return $XML::LibXML::__threads_shared ? 0 : 1;
}
-$VERSION = "2.0201"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0202"; # VERSION TEMPLATE: DO NOT CHANGE
sub new {
my $class = shift;
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
use XML::LibXML;
use vars qw ($VERSION);
-$VERSION = "2.0201"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0202"; # VERSION TEMPLATE: DO NOT CHANGE
sub CLONE_SKIP {
return $XML::LibXML::__threads_shared ? 0 : 1;
use XML::SAX::Base;
use XML::SAX::DocumentLocator;
-$VERSION = "2.0201"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0202"; # VERSION TEMPLATE: DO NOT CHANGE
@ISA = ('XML::SAX::Base');
sub CLONE_SKIP {
use XML::LibXML;
$doc = XML::LibXML->new->parse_file($url);
- $xmlschema = XML::LibXML::Schema->new( location => $filename_or_url );
- $xmlschema = XML::LibXML::Schema->new( string => $xmlschemastring );
+ $xmlschema = XML::LibXML::Schema->new( location => $filename_or_url, no_network => 1 );
+ $xmlschema = XML::LibXML::Schema->new( string => $xmlschemastring, no_network => 1 );
eval { $xmlschema->validate( $doc ); };
=head1 DESCRIPTION
=item new
- $xmlschema = XML::LibXML::Schema->new( location => $filename_or_url );
- $xmlschema = XML::LibXML::Schema->new( string => $xmlschemastring );
+ $xmlschema = XML::LibXML::Schema->new( location => $filename_or_url, no_network => 1 );
+ $xmlschema = XML::LibXML::Schema->new( string => $xmlschemastring, no_network => 1 );
-The constructor of XML::LibXML::Schema may get called with either one of two
-parameters. The parameter tells the class from which source it should generate
-a validation schema. It is important, that each schema only have a single
-source.
+The constructor of XML::LibXML::Schema needs to be called with list of
+parameters. At least location or string parameter is required to specify source
+of schema. Optional parameter no_network set to 1 cause that parser would not
+access network and optional parameter recover set 1 cause that parser would not
+call die() on errors.
+
+It is important, that each schema only have a single source.
The location parameter allows one to parse a schema from the filesystem or a
-URL.
+(non-HTTPS) URL.
The string parameter will parse the schema from the given XML string.
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
use XML::LibXML;
use XML::LibXML::NodeList;
-$VERSION = "2.0201"; # VERSION TEMPLATE: DO NOT CHANGE
+$VERSION = "2.0202"; # VERSION TEMPLATE: DO NOT CHANGE
# should LibXML XPath data types be used for simple objects
# when passing parameters to extension functions (default: no)
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
=head1 VERSION
-2.0201
+2.0202
=head1 COPYRIGHT
);
}
+# TEST
pass;
# vim: ts=4 sts=4 sw=4 et:
use Errno qw(ENOENT);
+# TEST*533
+
##
# test values
my @goodWFStrings = (
my %badstrings = (
SIMPLE => '<?xml version="1.0"?>'."\n<A/>\n",
);
- my $parser = XML::LibXML->new;
+ my $parser = XML::LibXML->new(expand_entities => 1);
$parser->validation(1);
my $doc;
<bar/>
EOXML
- my $parser = XML::LibXML->new;
+ my $parser = XML::LibXML->new(expand_entities => 1);
$parser->validation(1);
eval { $parser->parse_string( $badxml ); };
# TEST
ok ($@, '->validate throws an exception');
- my $parser = XML::LibXML->new();
+ my $parser = XML::LibXML->new(load_ext_dtd => 1);
# TEST
ok ($parser->validation(1), '->validation returns 1');
# this one is OK as it's well formed (no DTD)
{
# tests if global callbacks are working
- my $parser = XML::LibXML->new();
+ my $parser = XML::LibXML->new(load_ext_dtd => 1);
# TEST
ok($parser, '$parser was init');
$doc = XML::LibXML::Document->new();
}
# used to get "Attempt to free unreferenced scalar" here
-ok(1, 'docfree Out of scope is OK - no "Attempt to free unreferenced scalar"');
+# TEST
+pass('docfree Out of scope is OK - no "Attempt to free unreferenced scalar"');
use XML::LibXML;
if ( XML::LibXML::LIBXML_VERSION >= 20510 ) {
- plan tests => 13;
+ plan tests => 17;
}
else {
plan skip_all => 'Skip No RNG Support compiled';
my $validfile = "test/relaxng/demo.xml";
my $invalidfile = "test/relaxng/invaliddemo.xml";
my $demo4 = "test/relaxng/demo4.rng";
+my $netfile = "test/relaxng/net.rng";
print "# 1 parse schema from a file\n";
{
}
+print "# 6 check that no_network => 1 works\n";
+{
+ my $rng = eval { XML::LibXML::RelaxNG->new( location => $netfile, no_network => 1 ) };
+ # TEST
+ like( $@, qr{I/O error : Attempt to load network entity}, 'RNG from file location with external import and no_network => 1 throws an exception.' );
+ # TEST
+ ok( !defined $rng, 'RNG from file location with external import and no_network => 1 is not loaded.' );
+}
+{
+ my $rng = eval { XML::LibXML::RelaxNG->new( string => <<'EOF', no_network => 1 ) };
+<?xml version="1.0" encoding="iso-8859-1"?>
+<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+ <include href="http://example.com/xml.rng"/>
+ <start>
+ <ref name="include"/>
+ </start>
+ <define name="include">
+ <element name="include">
+ <text/>
+ </element>
+ </define>
+</grammar>
+EOF
+ # TEST
+ like( $@, qr{I/O error : Attempt to load network entity}, 'RNG from buffer with external import and no_network => 1 throws an exception.' );
+ # TEST
+ ok( !defined $rng, 'RNG from buffer with external import and no_network => 1 is not loaded.' );
+}
+
} # Version >= 20510 test
use XML::LibXML;
if ( XML::LibXML::LIBXML_VERSION >= 20510 ) {
- plan tests => 8;
+ plan tests => 12;
}
else {
plan skip_all => 'No Schema Support compiled.';
my $badfile = "test/schema/badschema.xsd";
my $validfile = "test/schema/demo.xml";
my $invalidfile = "test/schema/invaliddemo.xml";
+my $netfile = "test/schema/net.xsd";
# 1 parse schema from a file
is( $result, 0, 'validate() with element returns 0' );
}
+# 5 check that no_network => 1 works
+{
+ my $schema = eval { XML::LibXML::Schema->new( location => $netfile, no_network => 1 ) };
+ # TEST
+ like( $@, qr{I/O error : Attempt to load network entity}, 'Schema from file location with external import and no_network => 1 throws an exception.' );
+ # TEST
+ ok( !defined $schema, 'Schema from file location with external import and no_network => 1 is not loaded.' );
+}
+{
+ my $schema = eval { XML::LibXML::Schema->new( string => <<'EOF', no_network => 1 ) };
+<?xml version="1.0" encoding="UTF-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <xsd:import namespace="http://example.com/namespace" schemaLocation="http://example.com/xml.xsd"/>
+</xsd:schema>
+EOF
+ # TEST
+ like( $@, qr{I/O error : Attempt to load network entity}, 'Schema from buffer with external import and no_network => 1 throws an exception.' );
+ # TEST
+ ok( !defined $schema, 'Schema from buffer with external import and no_network => 1 is not loaded.' );
+}
$parser = XML::LibXML->new;
#$parser->set_option(huge => 0);
+# TEST
ok(!$parser->get_option('huge'), "huge mode disabled by default");
$doc = eval { $parser->parse_string($evil_xml); };
+# TEST
isnt("$@", "", "exception thrown during parse");
+# TEST
like($@, qr/entity.*loop/si, "exception refers to entity reference loop");
$doc = eval { $parser->parse_string($benign_xml); };
+# TEST
is("$@", "", "no exception thrown during parse");
my $body = $doc->findvalue( '/lolz' );
+# TEST
is($body, 'haha', 'entity was parsed and expanded correctly');
exit;
use_ok('XML::LibXML::Reader');
};
+# TEST*100
my $file = "test/textReader/countries.xml";
{
my $reader = XML::LibXML::Reader->new(location => $file, {expand_entities => 1});
use strict;
use warnings;
-use Test::More tests => 290;
+use Test::More tests => 291;
use XML::LibXML;
{
my $p = XML::LibXML->new();
for my $opt (@all) {
- my $ret = (($opt =~ /^(?:load_ext_dtd|expand_entities)$/) ? 1 : 0);
+ my $ret = 0;
# TEST*$all
ok(
($p->get_option($opt)||0) == $ret
ok( $p->get_option('recover') == 2, ' TODO : Add test name' );
# TEST
- ok( $p->expand_entities() == 1, ' TODO : Add test name' );
+ ok( $p->expand_entities() == 0, 'expand_entities should default to false' );
# TEST
- ok( $p->load_ext_dtd() == 1, ' TODO : Add test name' );
+ ok( $p->load_ext_dtd() == 0, 'load_ext_dtd should default to false' );
+ $p->load_ext_dtd(1);
+ # TEST
+ ok( $p->load_ext_dtd() == 1, 'load_ext_dtd should be true after being set to true' );
$p->load_ext_dtd(0);
+ $p->expand_entities(1);
# TEST
- ok( $p->load_ext_dtd() == 0, ' TODO : Add test name' );
- $p->expand_entities(0);
+ ok( $p->expand_entities() == 1, 'expand_entities should be true after being set to true' );
# TEST
- ok( $p->expand_entities() == 0, ' TODO : Add test name' );
- $p->expand_entities(1);
+ ok( $p->load_ext_dtd() == 1, 'load_ext_dtd should be true after expand_entities is set to true' );
+ $p->expand_entities(0);
# TEST
- ok( $p->expand_entities() == 1, ' TODO : Add test name' );
+ ok( $p->expand_entities() == 0, 'expand_entities should be false after being set to false' );
}
{
-#!/usr/bin/perl -w
+#!/usr/bin/env perl
use strict;
use warnings;
</rdf:RDF></metadata></record></GetRecord></OAI-PMH>
END_OF_XML
+# TEST
eq_or_diff(
\@got_warnings,
[],
use XML::LibXML;
use Test::More tests => 8;
+# TEST
ok(my $doc = XML::LibXML::Document->new(), 'new document');
+# TEST
ok(my $elm = $doc->createElement('D:element'), 'create element');
+# TEST
ok($elm->setAttribute('xmlns:D', 'attribute'), 'set attribute');
$doc->setDocumentElement($elm); # XXX does not return true if successful
+# TEST
ok(my $str = $doc->toString(0), 'to string');
+# TEST
ok(my $par = XML::LibXML->new(), 'new parser');
+# TEST
ok( eval { $par->parse_string($str) } , 'parse string');
+# TEST
is($@, "", 'parse error');
+# TEST
like($str, qr{<D:element xmlns:D="attribute"/>}, 'xml element');
close($fh);
+ # TEST
is($buf, '', 'No warning emitted on load_html with recover => 2.');
}
my $h1 = \%{ $e1 };
my $h2 = \%{ $e2 };
+# TEST
isnt $h1,$h2, 'different references';
+# TEST
is $h1->{attr}, 'value1', 'affr for el 1';
+# TEST
is $h2->{attr}, 'value2', 'affr for el 2';
+# TEST
is "$e1", '<test1 attr="value1"/>', 'stringify for el 1';
+# TEST
is "$e2", '<test2 attr="value2"/>', 'stringify for el 2';
+# TEST
cmp_ok 0+$e1, '>', 1, 'num for el 1';
+# TEST
cmp_ok 0+$e2, '>', 1, 'num for el 2';
+# TEST
isnt 0+$e1,0+$e2, 'num for e1 and e2 differs';
my $e3 = $e1;
+# TEST
ok $e3 eq $e1, 'eq';
+# TEST
ok $e3 == $e1, '==';
+# TEST
ok $e1 ne $e2, 'ne';
+# TEST
ok $e1 != $e2, '!=';
my @children_1 = $foo->childNodes;\r
my @children_2 = $foo->childNodes;\r
\r
+# TEST\r
ok($children_1[0]->can('unique_key'), 'unique_key method available')\r
or exit -1;\r
\r
--- /dev/null
+<?xml version="1.0" encoding="iso-8859-1"?>
+<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+ <include href="http://example.com/xml.rng"/>
+ <start>
+ <ref name="include"/>
+ </start>
+ <define name="include">
+ <element name="include">
+ <text/>
+ </element>
+ </define>
+</grammar>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <xsd:import namespace="http://example.com/namespace" schemaLocation="http://example.com/xml.xsd"/>
+</xsd:schema>