.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "XML::Validate 3pm" .TH XML::Validate 3pm "2022-06-28" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" XML::Validate \- an XML validator factory .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& my $validator = new XML::Validate(Type => \*(AqLibXML\*(Aq); \& \& if ($validator\->validate($xml)) { \& print "Document is valid\en"; \& } else { \& print "Document is invalid\en"; \& my $message = $validator\->last_error()\->{message}; \& my $line = $validator\->last_error()\->{line}; \& my $column = $validator\->last_error()\->{column}; \& print "Error: $message at line $line, column $column\en"; \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" XML::Validate is a generic interface to different \s-1XML\s0 validation backends. For a list of backend included with this distribution see the \s-1README.\s0 .PP If you want to write your own backends, the easiest way is probably to subclass XML::Validate::Base. Look at the existing backends for examples. .SH "METHODS" .IX Header "METHODS" .ie n .IP "new(Type => $type, Options => \e%options)" 4 .el .IP "new(Type => \f(CW$type\fR, Options => \e%options)" 4 .IX Item "new(Type => $type, Options => %options)" Returns a new XML::Validate parser object of type \f(CW$type\fR. For available types see \s-1README\s0 or use 'BestAvailable' (see \&\*(L"\s-1BEST AVAILABLE\*(R"\s0). .Sp The optional argument Options can be used to supply a set of key-value pairs to the backend parser. See the documentation for individual backends for details of these options. .IP "validate($xml_string)" 4 .IX Item "validate($xml_string)" Attempts a validating parse of the \s-1XML\s0 document \f(CW$xml_string\fR and returns a true value on success, or undef otherwise. If the parse fails, the error can be inspected using \f(CW\*(C`last_error\*(C'\fR. .Sp Note that documents which don't specify a \s-1DTD\s0 or schema will be treated as valid. .Sp For DOM-based parsers, the \s-1DOM\s0 may be accessed by instantiating the backend module directly and calling the \f(CW\*(C`last_dom\*(C'\fR method \- consult the documentation of the specific backend modules. Note that this isn't formally part of the XML::Validate interface as non-DOM-based validators may added at some point. .IP "\fBlast_error()\fR" 4 .IX Item "last_error()" Returns the error from the last validate call. This is a hash ref with the following fields: .RS 4 .IP "\(bu" 4 message .IP "\(bu" 4 line .IP "\(bu" 4 column .RE .RS 4 .Sp Note that the error gets cleared at the beginning of each \f(CW\*(C`validate\*(C'\fR call. .RE .IP "\fBtype()\fR" 4 .IX Item "type()" Returns the type of backend being used. .IP "\fBversion()\fR" 4 .IX Item "version()" Returns the version of the backend .SH "ERROR REPORTING" .IX Header "ERROR REPORTING" When a call to validate fails to parse the document, the error may be retrieved using last_error. .PP On errors not related to the \s-1XML\s0 parsing methods will throw exceptions. Wrap calls with eval to catch them. .SH "BEST AVAILABLE" .IX Header "BEST AVAILABLE" The BestAvailable backend type will check which backends are available and give you the \*(L"best\*(R" of those. For the default order of preference see the \s-1README\s0 with this distribution, but this can be changed with the option PrioritisedList. .PP If Xerces and LibXML are available the following code will give you a LibXML backend: .PP .Vb 4 \& my $validator = new XML::Validate( \& Type => \*(AqBestAvailable\*(Aq, \& Options => { PrioritisedList => [ qw( MSXML LibXML Xerces ) ] }, \& ); .Ve .SH "KNOWN ISSUES" .IX Header "KNOWN ISSUES" There is a bug in versions 1.57 and 1.58 of XML::LibXML that causes an issue related to \s-1DTD\s0 loading. When a base parameter is used in conjunction with the load_ext_dtd method the base parameter is ignored and the current directory is used as the base parameter. In other words, when validating \s-1XML\s0 with LibXML any base parameter option will be ignored, which may result in unexpected \s-1DTD\s0 loading errors. This was reported as bug on November 30th 2005 and the bug report can be viewed here http://rt.cpan.org/Public/Bug/Display.html?id=16213 .SH "VERSION" .IX Header "VERSION" \&\f(CW$Revision:\fR 1.25 $ on \f(CW$Date:\fR 2006/04/19 10:16:19 $ by \f(CW$Author:\fR mattheww $ .SH "AUTHOR" .IX Header "AUTHOR" Nathan Carr, Colin Robertson .PP .SH "COPYRIGHT" .IX Header "COPYRIGHT" (c) \s-1BBC 2005.\s0 This program is free software; you can redistribute it and/or modify it under the \s-1GNU GPL.\s0 See the file \s-1COPYING\s0 in this distribution, or http://www.gnu.org/licenses/gpl.txt