Catmandu-XSD

 view release on metacpan or  search on metacpan

lib/Catmandu/XSD.pm  view on Meta::CPAN

            <xs:element name="bar" type="xs:string" maxOccurs="unbounded"/>
          </xs:sequence>
         </xs:complexType>
        </xs:element>
    </xs:schema>

And now the test.xml and test2.xml can be parsed with help of Catmandu::XSD:

    catmandu XSD --root '{}foo' --schemas test.xsd to YAML < test.xml
    --
    bar:
      - test

    catmandu XSD --root '{}foo' --schemas test.xsd to YAML < test2.xml
    --
    bar:
      - test
      - test

=head1 WILDCARDS

Some XSD Schema allow for C<any> or C<anyAttribute> specifications in the schema.
The L<Catmandu::XSD> modules can't guess in these cases what the schema implementation
is. These nodes will be parsed as L<XML::LibXML::Node>s in the
resulting documents. Catmandu output formats such as L<Catmandu::Exporter::JSON>
can't handle these XML::LibXML::Node nodes. You have to implement yourself a
L<Catmandu::Fix> to translate these values in to plain string, array or hash elements.

But in general a round trip should be problematic:

    catmandu XSD --root ... --schema wildcard.xsd to XSD  --root ... --schema wildcard.xsd < data.xml

=head1 MIXED ELEMENTS

ComplexType and ComplexContent in the XSD schema can be declared with the C<<mixed="true">> attribute.
This means that in the XML documents simple text and XML elements can be mixed as in:

      Hello, I'm <name>John</name> how can I <bold>help</bold> you?

In these cases it is not know if the elements are required as an hash or should be ignored. By
defaults L<Catmandu::XSD> will parse these elements as L<XML::LibXML::Node>s documents.
This behavious can be changed by setting the 'mixed' flag:

    # All mixed elements will be XML::LibXML::Node-s
    catmandu XSD --root ... --schema mixed.xsd  < data.xml

    # The mixed elements will be ignored, only the text will survive
    #
    #  Hello, I'm <name>John</name> how can I <bold>help</bold> you?
    #
    #  =>  Hello, I'm John how can I help you?
    catmandu XSD --root ... --schema mixed.xsd --mixed TEXTUAL < data.xml

    # The mixed text will be ignored, only the elements will survive
    #
    #  Hello, I'm <name>John</name> how can I <bold>help</bold> you?
    #
    #  =>  { name => 'John' , bold => 'help' }
    catmandu XSD --root ... --schema mixed.xsd --mixed STRUCTURAL < data.xml

    # The mixed elements will be a plain XML fragment string
    #
    #  Hello, I'm <name>John</name> how can I <bold>help</bold> you?
    #
    #  =>  $r = 'Hello, I'm <name>John</name> how can I <bold>help</bold> you?'
    catmandu XSD --root ... --schema mixed.xsd --mixed XML_STRING < data.xml

=head1 MODULES

=over

=item L<Catmandu::Importer::XSD>

Parse and validate XML data using an XSD file for structural data.

=item L<Catmandu::Exporter::XSD>

Serialize and validate XML data using an XSD file for structural data.

=item L<Catmandu::Fix::xpath_map>

Map XML from XSD-any elements into data fields using XPath expressions.

=back

=head1 BUGS, QUESTIONS, HELP

Use the github issue tracker for any bug reports or questions on this module:
https://github.com/LibreCat/Catmandu-XSD/issues

=head1 DISCLAIMER

This module is based on L<XML::Compile> and the L<Catmandu> framework.

L<XML::Compile> is the workhorse that forms the core of this module to
compile XSD file into parser and serializers.

L<Catmandu> is used to transform parsed XML into any format you like.
Catmandu contains a simple DSL languages called L<Catmandu::Fix> to create
small scripts to manipulate data. The L<Catmandu> toolkit is used by many
university libraries to process metadata collections.

For more information on Catmandu visit: http://librecat.org/Catmandu/
or follow the blog posts at: https://librecatproject.wordpress.com/

=head1 AUTHOR

Patrick Hochstenbach , C<< patrick.hochstenbach at ugent.be >>

=head1 LICENSE AND COPYRIGHT

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 L<http://dev.perl.org/licenses/> for more information.

=head1 SEE ALSO

L<XML::Compile> , L<Catmandu> , L<Template> , L<Catmandu::XML>



( run in 0.735 second using v1.01-cache-2.11-cpan-364913b4093 )