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 to 1 the parser will not access the network. Periodt, she stays offline.
  • recover β€” optional, and if you set it to 1 the parser will not call die() 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-parsed XML::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 an eval. 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


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