/usr/bin/schema2example is in libxml-compile-perl 1.58-2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | #!/usr/bin/perl
use warnings;
use strict;
use XML::Compile::Schema ();
use XML::Compile::Util qw/type_of_node/;
use Getopt::Long qw/GetOptions :config gnu_compat bundling/;
my ($xml_input, $root_type, @schemas, $outfile);
my $format = 'PERL';
my $show = 'ALL';
GetOptions
'format|f=s' => \$format
, "output|o=s" => \$outfile
, "schema|s=s" => \@schemas
, "show=s" => \$show
, "type|t=s" => \$root_type
, "xml|x=s" => \$xml_input;
$xml_input = '-' if @schemas && !defined $xml_input;
if(@ARGV)
{ die "ERROR: either use options or no options, not mixed\n"
if defined $xml_input && @ARGV;
($xml_input, @schemas) = @ARGV;
}
defined $xml_input
or die "ERROR: no input message specified\n";
@schemas
or die "ERROR: no schema's specified\n";
@schemas = map { split /\,/ } @schemas;
$format = uc $format;
die "ERROR: format must be either 'PERL' or 'XML'\n"
if $format ne 'PERL' && $format ne 'XML';
my $parser = XML::LibXML->new;
my $msg = $xml_input eq '-'
? $parser->parse_fh(\*STDIN)
: $parser->parse_file($xml_input);
my $top = $msg->documentElement;
$root_type ||= type_of_node $top;
my $schema = XML::Compile::Schema->new;
$schema->importDefinitions($_) for @schemas;
my $output = $schema->template
( $format
, $root_type
, show => $show
);
if($outfile)
{ open OUT, ">:utf8", $outfile
or die "ERROR: cannot write yaml to $outfile: $!\n";
print OUT $output;
close OUT
or die "ERROR: write error for $outfile: $!\n";
}
else
{ print $output;
}
exit 0;
__END__
=head1 NAME
schema2example - convert XML schema knowledge into Perl or XML examples
=head1 SYNOPSIS
schema2example xml-file schema-file(s) >outfile
schema2example -x xml-file -s schema-file(s) -o outfile
=head1 DESCRIPTION
XML schemas are quite hard to read, certainly when multiple name-spaces
are involved. The template() function in XML::Compile::Schema function
can help displaying the expected structure of a message; this module is
a wrapper around that function.
=head2 Options
You can either specify an XML message filename and one or more
schema filenames as arguments, or use the options.
=over 4
=item --xml|-x filename
The file which contains the xml message. A single dash means "stdin".
=item --schema|-s filename(s)
This option can be repeated, or the filenames separated by comma's, if
you have more than one schema file to parse. All imported and included
schema components have to be provided explicitly.
=item --type|-t TYPE
The type of the root element, required if the XML is not namespaceo
qualified, although the schema is. If not specified, the root element
is automatically inspected.
The TYPE notation is C<{namespace}localname>. Be warned to use quoting
on the UNIX command-line, because curly braces have a special meaning
for the shell.
=item --output|-o filename
By default, the output is to stdout.
=item --show STRING
A comma separated list of comment components which should be included,
by default C<ALL>. An empty string or C<NONE> will exclude all comments.
The STRING can also be a comma separated combination of C<struct>, C<type>,
C<occur>, and C<facets>.
=back
=head1 SEE ALSO
This module is part of Perl's XML-Compile distribution.
Website: F<http://perl.overmeer.net/xml-compile/>
=head1 LICENSE
Copyrights 2008 by Mark Overmeer. For other contributors
see ChangeLog.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
See F<http://www.perl.com/perl/misc/Artistic.html>
|