XML::Li...RelaxNG(3)
π NAME π
XML::LibXML::RelaxNG β it's the RelaxNG Schema Validation girlie β¨
User Contributed Perl Documentation, bestie β that's the manual she lives in ππ
β¨ SYNOPSIS β¨
use XML::LibXML;
$doc = XML::LibXML->new->parse_file($url);
$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 ); };
π¦ DESCRIPTION π¦
Okay so XML::LibXML::RelaxNG is literally just a tiny little frontend to libxml2's RelaxNG implementation. Like, she's not doing the heavy lifting herself, she's the main character holding the door open for libxml2. π«Ά
As of right now? She supports schema parsing and document validation. That's the whole vibe. Two things. Iconic, honestly. β¨
π METHODS π
πΈ new
$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 );
So the constructor of XML::LibXML::RelaxNG has to be called with a list of parameters, no cap. At least one of location, string or DOM is required, because she needs to know where the schema is coming from. π§
no_networkβ optional, and if you set it to1the parser will not access the network. Periodt, she stays offline.recoverβ optional, and if you set it to1the parser will not calldie()when it hits errors. She's choosing peace. π
IMPORTANT bestie: each schema can only have a single source. One. Don't be greedy. π
Now let's break down the three source options, because they all hit different:
locationβ lets you parse a schema straight from the filesystem or from a (non-HTTPS) URL. Note the non-HTTPS thing, she said what she said.stringβ parses the schema from the given XML string. Just hand her the string and go. β¨DOMβ lets you parse the schema from a pre-parsedXML::LibXML::Document. Already parsed? She loves that for you. π
HEADS UP: the constructor will die() if the schema does not meet the constraints of the RelaxNG specification. She is not playing about that spec. π
π validate
eval { $rngschema->validate( $doc ); };
This one lets you validate a (parsed) document against the given RelaxNG schema. The argument you pass in should be an XML::LibXML::Document object, okay?
Here's the tea: if this function succeeds, it returns 0. If it doesn't, it die()s and reports all the errors it found. π
Because of that,validate()should always be wrapped in aneval. Always. Non-negotiable. That's the whole reason the synopsis has it wrapped up all cozy like that. π«Ά
π AUTHORS π
Matt Sergeant, Christian Glahn, Petr Pajas π
β VERSION β
2.0213
π COPYRIGHT π
2001-2007, AxKit.com Ltd.
2002-2006, Christian Glahn.
2006-2009, Petr Pajas.
π LICENSE π
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Slay. π
okay that's the whole page bestie, you're officially RelaxNG-pilled π§β¨
perl v5.42.2 Β· 2026-05-25 Β· XML::Li...RelaxNG(3) β mwah, bye! πππ¦
π¦ where this page comes from
- fedora 43: perl-XML-LibXML 1:2.0213-1.fc43 Β· (GPL-1.0-or-later OR Artistic-1.0-Perl) AND MIT
- fedora 44: perl-XML-LibXML 1:2.0213-1.fc44 Β· (GPL-1.0-or-later OR Artistic-1.0-Perl) AND MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms