[Xml-compile] Sequence with minOccurs=0
Roman Daniel
roman.daniel at davosro.cz
Fri Jan 8 17:13:23 GMT 2010
Hi Mark,
I tried recently to process a "real" (our) world schema containing sequence
with minOccurs=3D"0",
but the script below failed with: error: required value for element `str'
missing at {http://my.cz}env
Is it a bug or an intention?
By such schema we just wanted to ensure that some elements in sequence
appears either all of them or none.
Is there some cleaner way how to accomplish this?
Roman Daniel
#!/usr/bin/perl
use strict;
use warnings;
use XML::Compile::Schema;
my $schema =3D XML::Compile::Schema->new(<<'END_SCHEMA');
<xs:schema
xmlns:xs=3D"http://www.w3.org/2001/XMLSchema"
xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance"
targetNamespace=3D"http://my.cz"
elementFormDefault=3D"qualified">
<xs:element name=3D"env">
<xs:complexType>
<xs:sequence>
<xs:element name=3D"first" type=3D"xs:string" />
<xs:sequence minOccurs=3D"0">
<xs:element name=3D"str" type=3D"xs:string" />
<xs:element name=3D"dt" type=3D"xs:date" />
</xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
END_SCHEMA
my $w =3D $schema->compile(WRITER =3D> "{http://my.cz}env");
my $doc =3D XML::LibXML::Document->new;
my $elem =3D $w->($doc, {first =3D> 'F'});
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/xml-compile/attachments/20100108/ec=
1f9364/attachment.htm
More information about the Xml-compile
mailing list