Skip to content

Instantly share code, notes, and snippets.

@c-alpha
Last active July 30, 2021 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c-alpha/be0c0a9f73fb388ef1a6b2a1ac28d3f8 to your computer and use it in GitHub Desktop.
Save c-alpha/be0c0a9f73fb388ef1a6b2a1ac28d3f8 to your computer and use it in GitHub Desktop.
Validate against W3C XML Schema (XSD) 1.1 in Perl
use XML::Compile::Schema; # XML::LibXML does not support W3C XML SChema 1.1 (but which we need)
my $xmlschemastring = q(<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
...
elementFormDefault="qualified"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
vc:minVersion="1.1">
<xs:element ...
</xs:schema>);
my $schema = XML::Compile::Schema->new($xmlschemastring);
my $reader = $schema->compile(READER => '{my_namespace}my_root_element');
my $conf = $reader->($my_xmlfile);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment