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

πŸ’– Catmandu::Exporter::XSD πŸ’–

okay bestie, welcome to Catmandu::Exporter::XSD, part of the User Contributed Perl Documentation situation ✨ this is the page for the exporter that takes your Perl data and turns it into XML that's actually valid, like a good little citizen πŸŽ€


✨ NAME ✨

Catmandu::Exporter::XSD β€” Export and validate XML documents πŸ¦‹


🌸 SYNOPSIS 🌸

    # Convert one shiporder YAML to XML
    catmandu convert YAML to XSD --root '{}shiporder'
                                 --schemas demo/order/*.xsd < shiporder.YAML

    # Same as above but store multiple shiporders in the YAML into a separate file
    catmandu convert YAML to XSD --root '{}shiporder'
                                 --schemas demo/order/*.xsd
                                 --split 1
                                 < shiporder.YAML

    # Same as above but use template toolkit to pack the XML into an container
    # (The xml record is stored in the 'xml' key which can be retrieved in the
    # template by [% xml %])
    catmandu convert YAML to XSD --root '{}shiporder'
                                 --schemas demo/order/*.xsd
                                 --template_before t/xml_header.tt
                                 --template t/xml_record.tt
                                 --template t/xml_footer.tt
                                 < shiporder.YAML

    use Catmandu;

    # Print to STDOUT
    my $exporter = Catmandu->exporter('XSD',
                        root => ...
                        schemas => ...
    );

    $exporter->add_many($arrayref);
    $exporter->add_many($iterator);
    $exporter->add_many(sub { });
    $exporter->add($hashref);

    $exporter->commit;

no cap, those code blocks are verbatim, I would never touch them πŸ’…


🌈 DESCRIPTION 🌈

So basically this is a Catmandu::Exporter for converting Perl into valided XML documents using an XSD schema file. It's giving "your data, but make it schema-compliant" πŸ‘‘ ✨


πŸŽ€ CONFIGURATION πŸŽ€

Every option, every default, let's go 🫢

  • file β€” Write output to a local file given by its path. Alternatively a scalar reference can be passed to write to a string. iconic behavior honestly
  • fh β€” Write output to an IO::Handle. If not specified, Catmandu::Util::io is used to create the output stream from the "file" argument or by using STDOUT. lowkey the fallback queen πŸ’œ
  • split β€” Optional. Don't write to the file (or STDOUT) and split the output documents into one or more files. E.g.
        catmandu ... to XSD --root ... --schemas ... --split 1  < data
  • split_pattern β€” Optional. Use a FORMAT as template for naming output files. Uses the '_id' field in the data or an incremental counter as input. E.g.
        # Creates 000001.xml , 000002.xml, etc
        catmandu ... to XSD --root ... --schemas ... --split 1 --split_pattern '%-6.6d.xml' < data
  • split_directory β€” Optional. Specify the directory in which the split files need to be written. πŸ“
  • template β€” Optional. A template toolkit template to be used for creating each XML output record. Gets as input the input data plus the XML serialized form in the 'xml' field. the way that it feeds you the xml too?? so thoughtful 😭
  • template_before β€” Optional. The template toolkit template to be used as XML header. 🌸
  • template_after β€” Optional. The template toolkit template to be used as XML footer. 🌸
  • fix β€” An ARRAY of one or more fixes or file scripts to be applied to imported items. get that data cleaned up bestie 🧚
  • 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. no schemas, no vibes πŸ’€
  • prefixes β€” Optional. An array or comma delimited string of namespace prefixes to be used hand 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. The handling of mixed element content. One of ATTRIBUTES (default), TEXTUAL, STRUCTURAL, XML_NODE, XML_STRING, CODE reference. See also Catmandu::XSD and XML::Compile::Translate::Reader. note that ATTRIBUTES is the default, bestie, don't forget it πŸ‘‘

πŸ’… METHODS πŸ’…

Every Catmandu::Importer is a Catmandu::Iterable all its methods are inherited. so like, you get a whole inheritance glow-up for free ✨


πŸ¦‹ SEE ALSO πŸ¦‹

  • Catmandu::Exporter
  • Catmandu::XSD
  • Template

πŸ‘‘ AUTHOR πŸ‘‘

Patrick Hochstenbach , "patrick.hochstenbach at ugent.be" β€” ty king 🫢


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.


okay so that's the whole page bestie, every flag, every default, every ... left exactly where it was, I did not touch a single character of the code πŸ’…

and for the cute sign-off: this was perl v5.36.0, dated 2022-11-29, filed under Catman...er::XSD(3pm) β€” periodt βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from