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 145 146 147 148 149 150 151 152 153 154
|
#!/usr/bin/env perl
use warnings;
use strict;
use lib 'lib','t';
use TestTools;
use XML::Compile::Schema;
use XML::Compile::Tester;
use Test::More tests => 33;
my $TestNS2 = "http://second-ns";
set_compile_defaults
elements_qualified => 'NONE';
my $schema = XML::Compile::Schema->new( <<__SCHEMA__ );
<schemas>
<schema targetNamespace="$TestNS"
xmlns="$SchemaNS"
xmlns:me="$TestNS">
<element name="test1" type="me:c1" />
<complexType name="c1">
<sequence>
<element name="e1_a" type="int" />
<element name="e1_b" type="int" />
</sequence>
<attribute name="a1_a" type="int" />
</complexType>
<group name="g2">
<sequence>
<element name="g2_a" type="int" />
<element name="g2_b" type="int" />
</sequence>
</group>
<element name="test2">
<complexType>
<sequence>
<element name="e2_a" type="int" />
<group ref="me:g2" />
<element name="e2_b" type="int" />
</sequence>
</complexType>
</element>
<element name="test3">
<complexType>
<sequence>
<group ref="me:g3" minOccurs="0" maxOccurs="unbounded" />
</sequence>
</complexType>
</element>
<group name="g3">
<choice>
<element name="g3_a" type="int"/>
<element name="g3_b" type="int"/>
</choice>
</group>
</schema>
<schema targetNamespace="$TestNS2"
xmlns="$SchemaNS"
xmlns:first="$TestNS">
<element name="test4">
<complexType>
<sequence>
<element ref="first:test1" />
</sequence>
</complexType>
</element>
<element name="test5">
<complexType>
<sequence>
<element ref="first:test1" maxOccurs="unbounded" />
</sequence>
</complexType>
</element>
</schema>
</schemas>
__SCHEMA__
ok(defined $schema);
#
# element as reference to an element
#
my %r1_a = (a1_a => 10, e1_a => 11, e1_b => 12);
test_rw($schema, "{$TestNS2}test4" => <<__XML, {test1 => \%r1_a});
<test4>
<test1 a1_a="10">
<e1_a>11</e1_a>
<e1_b>12</e1_b>
</test1>
</test4>
__XML
#
# element groups
#
my %r2_a = (e2_a => 20, g2_a => 22, g2_b => 23, e2_b => 21);
test_rw($schema, test2 => <<__XML, \%r2_a);
<test2>
<e2_a>20</e2_a>
<g2_a>22</g2_a>
<g2_b>23</g2_b>
<e2_b>21</e2_b>
</test2>
__XML
#
# ref to choice
#
my %r3_a = (gr_g3 => [ {g3_a => 30}, {g3_a => 31}, {g3_b => 32}, {g3_a => 33} ]);
test_rw($schema, test3 => <<__XML, \%r3_a);
<test3>
<g3_a>30</g3_a>
<g3_a>31</g3_a>
<g3_b>32</g3_b>
<g3_a>33</g3_a>
</test3>
__XML
#
# ref repeat
#
my %r5_a = (a1_a => 40, e1_a => 41, e1_b => 42);
my %r5_b = (a1_a => 43, e1_a => 44, e1_b => 45);
test_rw($schema, "{$TestNS2}test5" => <<__XML, {test1 => [ \%r5_a, \%r5_b ]});
<test5>
<test1 a1_a="40">
<e1_a>41</e1_a>
<e1_b>42</e1_b>
</test1>
<test1 a1_a="43">
<e1_a>44</e1_a>
<e1_b>45</e1_b>
</test1>
</test5>
__XML
|