Skip Menu |

This queue is for tickets about the XML-Compile CPAN distribution.

Report information
The Basics
Id: 51264
Status: resolved
Priority: 0/
Queue: XML-Compile

People
Owner: Nobody in particular
Requestors: roman.daniel [...] gtsnovera.cz
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: writer and element with nillable="true" minOccurs="0"
I encounter a strange (for me) behaviour of XML::Compile::Schema (1.07) regarding the combination above. I have an outer element of complex type (sequence) and inner element having nillable=3D"true" and minOccurs=3D"0". If I call writer for the outer element and don't supply the inner element key in the hash, the inner element is still rendered in the output - as empty XML element. If the element is not nillable it doesn't appear at all. Look at the example use strict; use warnings; use XML::Compile::Schema; for my $nillable ( '', 'nillable=3D"true"' ) { my $schema =3D XML::Compile::Schema->new( schema($nillable) ); my $writer =3D $schema->compile( WRITER =3D> "{http://myns.cz/}outer" ); my $reader =3D $schema->compile( READER =3D> "{http://myns.cz/}outer" ); my $doc =3D XML::LibXML::Document->new; my $e =3D $writer->( $doc, {} ); $doc->setDocumentElement($e); warn "NILLABLE: $nillable\n", $doc->toString(1), "\n\n"; # check, whether reader can accept this my $x =3D $reader->($doc->toString); } sub schema { my $nillable =3D shift; return <<"END_XML"; } <?xml version=3D"1.0"?> <xs:schema xmlns:xs=3D"http://www.w3.org/2001/XMLSchema" elementFormDefault=3D"qualified" targetNamespace=3D"http://myns.cz/"> <xs:element name=3D"outer"> <xs:complexType> <xs:sequence> <xs:element name=3D"inner" minOccurs=3D"0" $nillable> <xs:simpleType> <xs:restriction base=3D"xs:string"> <xs:minLength value=3D"1"/> </xs:restriction> </xs:simpleType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> END_XML And its output: NILLABLE: <?xml version=3D"1.0"?> <x0:outer xmlns:x0=3D"http://myns.cz/"/> NILLABLE: nillable=3D"true" <?xml version=3D"1.0"?> <x0:outer xmlns:x0=3D"http://myns.cz/" xmlns:xsi=3D" http://www.w3.org/2001/XMLSchema-instance"> <x0:inner></x0:inner> </x0:outer> error: string `' does not have minimum length 1 at { http://myns.cz/}outer/inner#facet When element is not nillable it doesn't appear in the XML at all. If it is nillable it appears as empty, which is unacceptable for reader, since the content of the element is unempty string. Is it a bug or am I missing something? Thanks for any clue, Roman Daniel
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #51264] writer and element with nillable="true" minOccurs="0"
Date: Tue, 10 Nov 2009 12:45:35 +0100
To: Roman Daniel via RT <bug-XML-Compile [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Roman Daniel via RT (bug-XML-Compile@rt.cpan.org) [091110 09:23]: Try this: XML/Compile/Translate/Writer.pm sub makeSimpleElement { my ($self, $path, $tag, $st) = @_; sub { my ($doc, $data) = @_; return $doc->importNode($data) if UNIVERSAL::isa($data, 'XML::LibXML::Element'); $data = $data->{_} if ref $data eq 'HASH'; my $value = $st->($doc, $data); + defined $value + or return (); my $node = $doc->createElement($tag); error __x"expected single value for {tag}, but got {type}" , tag => $tag, type => ref($value) if ref $value eq 'ARRAY' || ref $value eq 'HASH'; The bug probably had nothing to do with nillable on its self, but more with a missing check on the success of the creation of a simpleElement. My whole test suite (>2500) nowhere tumbled over this... probably only triggered in complex combinations of simpleType attributes. -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Subject: Re: [rt.cpan.org #51264] writer and element with nillable="true" minOccurs="0"
Date: Tue, 10 Nov 2009 12:56:05 +0100
To: Roman Daniel via RT <bug-XML-Compile [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Roman Daniel via RT (bug-XML-Compile@rt.cpan.org) [091110 09:23]: I forsee a next bug-report: it seems that the 'inner' value is now lost... Investigating. -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #51264] writer and element with nillable="true" minOccurs="0"
Date: Tue, 10 Nov 2009 13:10:28 +0100
To: Mark Overmeer via RT <bug-XML-Compile [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Mark Overmeer via RT (bug-XML-Compile@rt.cpan.org) [091110 11:58]: Show quoted text
> Queue: XML-Compile > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=51264 > > > * Roman Daniel via RT (bug-XML-Compile@rt.cpan.org) [091110 09:23]: > > I forsee a next bug-report: it seems that the 'inner' value is now lost... > Investigating.
Oh, gladly that only was caused by a bug in my test-script. MarkOv
resolved in 1.09
Subject: Re: [rt.cpan.org #51264] Resolved: writer and element with nillable="true" minOccurs="0"
Date: Sat, 5 Dec 2009 12:20:13 +0100
To: bug-XML-Compile [...] rt.cpan.org
From: Roman Daniel <roman.daniel [...] davosro.cz>
Hi Mark, I installed 1.09, the simpleType case for minOccurs, nillable is OK, but I recently came across the case when minOccurs=0 nillable="true" and the element is of complex type. The script below yields: { addressId => bless({ sign => "+", value => [100] }, "Math::BigInt"), } error: complex `x0:address' requires data at {http://address.cz} updateAddress/address use strict; use warnings; use XML::Compile::Schema; use Data::Dump qw(pp); my $ns = "http://address.cz"; my $schema = XML::Compile::Schema->new(schema()); my $reader = $schema->compile(READER => "{$ns}updateAddress"); my $writer = $schema->compile(WRITER => "{$ns}updateAddress"); my $doc = XML::LibXML::Document->new; my $fields = $reader->(<<"END_UA"); <updateAddress xmlns="$ns"><addressId>100</addressId></updateAddress> END_UA # reader is OK pp($fields); my $elem = $writer->($doc, $fields); sub schema { return <<'END_XML' } <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://address.cz" targetNamespace="http://address.cz" elementFormDefault="qualified"> <!-- --> <!-- --> <!-- --> <xs:complexType name="typeAddress"> <xs:sequence> <xs:element name="street" type="xs:string" /> <xs:element name="city" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:element name="updateAddress"> <xs:complexType> <xs:sequence> <xs:element name="addressId" type="xs:unsignedLong" /> <xs:element name="address" type="tns:typeAddress" minOccurs="0" nillable="true" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> END_XML 2009/12/1 Mark Overmeer via RT <bug-XML-Compile@rt.cpan.org> Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=51264 > > > According to our records, your request has been resolved. If you have any > further questions or concerns, please respond to this message. > >
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #51264] Resolved: writer and element with nillable="true" minOccurs="0"
Date: Wed, 23 Dec 2009 23:56:52 +0100
To: Roman Daniel via RT <bug-XML-Compile [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Roman Daniel via RT (bug-XML-Compile@rt.cpan.org) [091205 11:20]: Show quoted text
> Queue: XML-Compile > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=51264 > > > I installed 1.09, the simpleType case for minOccurs, nillable is OK, > but I recently came across the case > when minOccurs=0 nillable="true" and the element is of complex type.
Not easy to find, but easy to fix in XML::Compile::Translate::Writer sub makeElementNillable { my ($self, $path, $ns, $childname, $do, $value, $tag) = @_; ... sub { my ($doc, $value) = @_; - defined $value && $value eq 'NIL' - or return $do->($doc, $value); + defined $value or return; + $value eq 'NIL' or return $do->($doc, $value); -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
resolved in 1.10, to be released later today