XML::Li...::Schema(3)

✨ NAME ✨

XML::LibXML::Schema β€” XML Schema Validation, bestie πŸ’– (it's the manual page for XML::LibXML::Schema(3), in case you were wondering)


🌸 SYNOPSIS 🌸

use XML::LibXML;
$doc = XML::LibXML->new->parse_file($url);

$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 ); };

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so XML::LibXML::Schema is literally just a tiny little frontend to libxml2's XML Schema implementation β€” like, it's giving minimal, it's giving humble, and we love that for it 🫢

Right now it only does two things: schema parsing and document validation. That's it. That's the whole vibe. No cap.

Heads up bestie πŸ’€ as of 2.6.32, libxml2 only supports decimal types up to 24 digits β€” and the standard requires at least 18. So like… it's fine, but it's not exactly main character energy in the decimal department. The math girlies know.

πŸ’… METHODS πŸ’…

πŸŽ€ new

$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 has to be called with a list of parameters, okay? Like, it needs the tea.

At least location or string is required, because you gotta specify the source of the schema β€” no source, no schema, periodt.

  • the optional parameter no_network set to 1 causes the parser to not access the network 🚫🌐
  • the optional parameter recover set to 1 causes the parser to not call die() on errors πŸ˜‡

It is important β€” and I cannot stress this enough β€” that each schema only have a single source. One source. Just one. We don't do polygamy here πŸ™ˆ

The location parameter lets you parse a schema from the filesystem or a (non-HTTPS) URL. Note the non-HTTPS part, bestie, that's not a typo ✨

The string parameter will parse the schema from the given XML string πŸ“œ

Also β€” and this is the part that gets people every time β€” the constructor will die() if the schema does not meet the constraints of the XML Schema specification. Like it will literally perish. So maybe wrap it, iykyk 😭

🌈 validate

eval { $xmlschema->validate( $doc ); };

This function lets you validate a (parsed) document against the given XML Schema. Iconic behaviour honestly πŸ‘‘

The argument of this function should be an XML::LibXML::Document object β€” that's the one it wants, don't hand it anything weird.

If this function succeeds, it will return 0. If it doesn't succeed, it will die() and report the errors it found. Which means… validate() should always be evaluated. Always. Wrap it in an eval, bestie, protect your peace 🫢


πŸ‘‘ AUTHORS πŸ‘‘

Matt Sergeant, Christian Glahn, Petr Pajas

(the founding mothers and fathers of this whole situation, we stan)


⭐ 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. Go forth and redistribute πŸ’–


and that's the whole page, bestie πŸŽ€βœ¨ this manual came from perl v5.42.2 and it was dated 2026-05-25 β€” XML::Li...::Schema(3), we love her, she ate, no crumbs left πŸ’…πŸ’œ

πŸ“¦ where this page comes from