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
#!/usr/local/bin/perl
#------------------------------Basic-----------------------------------------#
use warnings;
use strict;
#----------------------------- Specific Module ------------------------------#
use Data::Dumper;
use XML::Compile::Schema;
use XML::LibXML::Reader;
#----------------------------- XSD Analyse ----------------------------------#
my $xsd = "T://RoGa//test.xsd";
my $schema = XML::Compile::Schema->new($xsd);
# This will print a very basic description of what the schema describes
#$schema->printIndex();
# This will print a expample whit posible values.
warn $schema->template( 'PERL', 'CQA' );
#----------------------------- XML Data -------------------------------------#
my $data = {
INFO => {
owner => 'R.Galli',
name => 'Perl-XML',
description => 'Perl-XML-DES',
date => '2014-12-13',
status => '1',
version => '9.08',
},
LOG => { message => 'LOG INFO 1', },};
#----------------------------- XML Out --------------------------------------#
my $doc = XML::LibXML::Document->new( '1.0', 'UTF-8' );
my $write = $schema->compile( WRITER => 'CQA' );
my $xml = $write->( $doc, $data );
$doc->setDocumentElement($xml);
print $doc->toString(1); # 1 indicates "pretty print";
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
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="CQA" minOccurs='1'>
<xs:complexType>
<xs:sequence>
<xs:element ref="INFO" minOccurs='1' maxOccurs='1'/>
<xs:element ref="LOG" minOccurs='0' maxOccurs='1'/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="INFO">
<xs:complexType>
<xs:sequence>
<xs:element ref="owner" minOccurs='1' maxOccurs='1'/>
<xs:element ref="name" minOccurs='1' maxOccurs='1'/>
<xs:element ref="description" minOccurs='1' maxOccurs='1'/>
<xs:element ref="date" minOccurs='1' maxOccurs='1'/>
<xs:element ref="status" minOccurs='1' maxOccurs='1'/>
<xs:element ref="version" minOccurs='1' maxOccurs='1'/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="LOG">
<xs:complexType>
<xs:sequence>
<xs:element ref="message" maxOccurs='unbounded'/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element type="xs:string" name="owner"/>
<xs:element type="xs:string" name="name"/>
<xs:element type="xs:string" name="description"/>
<xs:element type="xs:date" name="date"/>
<xs:element type="xs:integer" name="status"/>
<xs:element type="xs:float" name="version"/>
<xs:element type="xs:string" name="message"/>
</xs:schema>