Catman...er::XSD(3pm)

πŸ’– Catmandu::Importer::XSD πŸ’–

okay bestie, gather round, because this one is a whole mood. we're looking at Catmandu::Importer::XSD, a page from the User Contributed Perl Documentation set (the header line calls it Catman...er::XSD(3pm), which is giving "truncated by the terminal, but make it fashion" πŸ’…).


✨ NAME ✨

Catmandu::Importer::XSD β€” Import and validate serialized XML documents πŸ¦‹


🌸 SYNOPSIS 🌸

    # Compile an XSD schema file and parse one shiporder.xml file
    catmandu convert XSD --root '{}shiporder'
                         --schemas demo/order/*.xsd
                         to YAML < shiporder.xml

    # Same as above but parse more than one file into an array of records
    catmandu convert XSD --root '{}shiporder'
                         --schemas demo/order/*.xsd
                         --files 'data/*.xml'
                         to YAML

    # Same as above but all array of records are in a XML container file
    catmandu convert XSD --root '{}shiporder'
                         --schemas demo/order/*.xsd
                         --xpath '/Container/List//Record/Payload/*'
                         to YAML < data/container.xml

    # In Perl
    use Catmandu;

    my $importer = Catmandu->importer('XSD',
                file => 'ex/data.xml'
                root => ...,
                schemas => [ ...]
    );

    my $n = $importer->each(sub {
        my $hashref = $_[0];
        # ...
    });

no cap, that last bit is the one you'll actually use in your Perl scripts πŸ‘‘


πŸ’œ DESCRIPTION πŸ’œ

okay so this is a Catmandu::Importer β€” and its whole job? parsing and validating XML data using one or more XSD schema files. it's giving "glow up your XML, but with receipts" ✨


πŸŽ€ CONFIGURATION πŸŽ€

  • file β€” read input from a local file, and you give it the path. alternatively you can hand it a scalar reference and it'll read from that string instead. iconic flexibility 🫢
  • fh β€” read input from an IO::Handle. if you don't specify one, Catmandu::Util::io is used to build the input stream from the "file" argument, or by falling back to STDIN. default queen behavior πŸ’…
  • files β€” optional! instead of reading content from standard input, use the 'files' parameter as a glob for one or more filenames. e.g.
    catmandu ... --files 'data/input/*.xml'
  • examples β€” optional. doesn't actually do anything β€” it just shows you an example output of how a document should be structured in the given XSD scheme. a little preview, a little vibe check πŸ‘€ e.g.
    catmandu convert XSD --root {}shiporder --schemas "t/demo/ead/*xsd" --example 1 to YAML
  • fix β€” an ARRAY of one or more fixes or file scripts that get applied to imported items. your lil makeover station 🧚
  • root β€” Required. the name (and namespace) of the root element of the XML document. e.g.:
    {}shiporder
    {http://www.loc.gov/mods/v3}mods
    {urn:isbn:1-931666-22-9}ead
  • schemas β€” Required. an array or comma separated list of XSD schema locations.
  • xpath β€” optional. an XPath expression: the XML container in which the PNX record can be found. default is:
    /oai:OAI-PMH/oai:ListRecords//oai:record/oai:metadata/*
  • prefixes β€” optional. an array or comma delimited string of namespace prefixes to be used when handling XML files. e.g.
    # On the command line:
    catmandu ... --prefixes ead:urn:isbn:1-931666-22-9,...

    # In Perl
    prefixes => [
        ead => 'urn:isbn:1-931666-22-9' ,
        ... => ...
    ]
  • mixed β€” optional. how mixed element content gets handled. one of ATTRIBUTES (that's the default), TEXTUAL, STRUCTURAL, XML_NODE, XML_STRING, or a CODE reference. see also Catmandu::XSD and XML::Compile::Translate::Reader.
  • any_element β€” optional. how <any"> content in schemas gets handled. one of TAKE_ALL (default: process as XML::LibXML::Node), SKIP_ALL (just ignore these), XML_STRING (process as string), or CODE (provide a reference to parse the data). see XML::Compile::Translate::Reader.

πŸ¦‹ METHODS πŸ¦‹

every Catmandu::Importer is a Catmandu::Iterable, so all its methods are inherited. periodt. πŸ’…


🌈 SEE ALSO 🌈

  • Catmandu::Importer
  • Catmandu::XSD

πŸ‘‘ AUTHOR πŸ‘‘

Patrick Hochstenbach, "patrick.hochstenbach at ugent.be" β€” legend behavior, fr fr 🫢


This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See <http://dev.perl.org/licenses/> for more information.


and that's the whole page, bestie! πŸŽ€ this one shipped as perl v5.36.0, dated 2022-11-29, under the header Catman...er::XSD(3pm) β€” go forth and validate your XML, you absolute main character πŸŒŸπŸ’œ

πŸ“¦ where this page comes from