Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: dexter [...] cpan.org
Cc:
AdminCc:

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



Subject: XML::Compile - schema2example should generate vaild XML
schema2example should generate XML file which can be validated in. with xml2yaml command. This patch resolves this problem: * adds xmlns:xsi (used by xsi:type attributes) * generates correct XML comments (must not contain "--" string inside) === modified file 'lib/XML/Compile/Schema.pm' --- lib/XML/Compile/Schema.pm 2011-11-22 13:29:28 +0000 +++ lib/XML/Compile/Schema.pm 2011-11-22 13:49:49 +0000 @@ -336,8 +336,8 @@ , !$args{use_default_namespace} ); - $table->{&SCHEMA2001} ||= {prefix => 'xs', uri => SCHEMA2001, used => 0}; - $table->{&SCHEMA2001i} ||= {prefix => 'xsi', uri => SCHEMA2001i, used => 0}; + $table->{&SCHEMA2001} ||= {prefix => 'xs', uri => SCHEMA2001, used => 1}; + $table->{&SCHEMA2001i} ||= {prefix => 'xsi', uri => SCHEMA2001i, used => 1}; my $transl = XML::Compile::Translate->new ( 'TEMPLATE' === modified file 'lib/XML/Compile/Translate/Template.pm' --- lib/XML/Compile/Translate/Template.pm 2011-11-22 13:29:28 +0000 +++ lib/XML/Compile/Translate/Template.pm 2011-11-22 13:33:02 +0000 @@ -808,9 +808,9 @@ my $header = $doc->createComment( <<_HEADER . ' ' ); BE WARNED: in most cases, the example below cannot be used without - -- interpretation. The comments will guide you. - -- Produced by $pkg version $VERSION - -- on $now + interpretation. The comments will guide you. + Produced by $pkg version $VERSION + on $now _HEADER unless($args{skip_header})
Subject: Re: [rt.cpan.org #72616] XML::Compile - schema2example should generate vaild XML
Date: Tue, 22 Nov 2011 15:58:18 +0100
To: Piotr Roszatycki via RT <bug-XML-Compile [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Piotr Roszatycki via RT (bug-XML-Compile@rt.cpan.org) [111122 14:21]: Show quoted text
> Tue Nov 22 09:20:46 2011: Request 72616 was acted upon. > Transaction: Ticket created by DEXTER > Queue: XML-Compile > Subject: XML::Compile - schema2example should generate vaild XML > > schema2example should generate XML file which can be validated in. with > xml2yaml command.
That's not possible: the XML output will describe, for instance, all alternatives of a choice. So: the example will (in general) not validate. Although, it should be attempted to produce a correct XML file... Show quoted text
> * generates correct XML comments (must not contain "--" string inside)
Accepted. Show quoted text
> * adds xmlns:xsi (used by xsi:type attributes) > + $table->{&SCHEMA2001i} ||= {prefix => 'xsi', uri => SCHEMA2001i,
Can you explain me how the example generator would be able to produce xsi:type attributes? -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
An example: Schema files at https://gist.github.com/1373668 Command: perl -MXML::Compile::Schema -le '$r=shift @ARGV; $s=XML::Compile::Schema->new; $s->importDefinitions($_) for @ARGV; print $s->template("XML", $r, show=>"ALL")' '{http://com.osa.mdsp.enabler.sei/SMSEnabler/V2_0/SMSSenderSEI}sendSMS' com.*.xsd Output: <x0:sendSMS xmlns:tns2="http://com.osa.mdsp.enabler.sei.eto/SMSEnabler/V2_0" xmlns:tns4="http://com.osa.mdsp.enabler.ecf" xmlns:x0="http://com.osa.mds p.enabler.sei/SMSEnabler/V2_0/SMSSenderSEI" xsi:type="unnamed complex"> <!-- BE WARNED: in most cases, the example below cannot be used without -- interpretation. The comments will guide you. -- Produced by XML::Compile::Translate::Template version 1.22 -- on Tue Nov 22 22:09:02 2011 --> <!-- sequence of x0:ctx, x0:sms --> <x0:ctx xsi:type="tns4:InvocationContext"> <!-- is nillable --> <!-- sequence of tns4:properties --> <tns4:properties xsi:type="xs:string"> (...) Validation of autogenerated XML example file fails: $ xml2yaml -s com.osa.mdsp.enabler.ecf.xsd,com.osa.mdsp.enabler.sei.eto_SMSEnabler_V2_ 0.xsd,com.osa.mdsp.enabler.sei.exception_SMSEnabler_V2_0.xsd,com.osa.mds p.enabler.sei_SMSEnabler_V2_0_SMSSenderSEI.xsd -x example.xml a.xml:1: namespace error : Namespace prefix xsi for type on sendSMS is not defined om.osa.mdsp.enabler.sei/SMSEnabler/V2_0/SMSSenderSEI" xsi:type="unnamed complex" ^ Additional xmlns:xsi fixes example.xml
Subject: Re: [rt.cpan.org #72616] XML::Compile - schema2example should generate vaild XML
Date: Tue, 22 Nov 2011 22:57:35 +0100
To: Piotr Roszatycki via RT <bug-XML-Compile [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Piotr Roszatycki via RT (bug-XML-Compile@rt.cpan.org) [111122 21:13]: Show quoted text
> $s->template("XML", $r, show=>"ALL")'
Ah, of course: show => 'ALL' contains show_type which does it. Thanks for the patch. I'll make a release this week. -- 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 #72616] XML::Compile - schema2example should generate vaild XML
Date: Wed, 23 Nov 2011 09:46:58 +0100
To: Piotr Roszatycki via RT <bug-XML-Compile [...] rt.cpan.org>
From: Mark Overmeer <solutions [...] overmeer.net>
* Piotr Roszatycki via RT (bug-XML-Compile@rt.cpan.org) [111122 14:21]: Show quoted text
> Tue Nov 22 09:20:46 2011: Request 72616 was acted upon. > Transaction: Ticket created by DEXTER > Queue: XML-Compile > Subject: XML::Compile - schema2example should generate vaild XML > > * adds xmlns:xsi (used by xsi:type attributes) > * generates correct XML comments (must not contain "--" string inside)
both changes accepted. Released (with other improvements) as version 1.23 -- Thanks for the contribution. MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
On Śr 23 Lis 2011, 03:47:09, solutions@overmeer.net wrote: Show quoted text
> > * adds xmlns:xsi (used by xsi:type attributes) > > * generates correct XML comments (must not contain "--" string
inside) Show quoted text
> > both changes accepted. Released (with other improvements) as version
1.23 Nice. But also I've found that nsxml:xsi is added also when this namespace is not really used in XML document. I'm not exactly sure if it is possible to define this namespace only if its usage is detected further in document. Example: $ perl -MYAML=LoadFile,Dump -MXML::Compile::Schema -le '$d=LoadFile(shift @ARGV); $r=shift @ARGV; ($a=$r)=~s/{.*}//; $x=XML::LibXML::Document->new("1.0", "UTF-8"); $x=XML::Compile::Schema- Show quoted text
>new(\@ARGV)->compile(WRITER => $r)->($x, $d->{$a}); print $x- >toString(1)' sgw-sms-sender-example.yml
'{http://com.osa.mdsp.enabler.sei/SMSEnabler/V2_0/SMSSenderSEI}sendSMS' com.*.xsd <x0:sendSMS xmlns:tns2="http://com.osa.mdsp.enabler.sei.eto/SMSEnabler/V2_0" xmlns:tns4="http://com.osa.mdsp.enabler.ecf" xmlns:x0="http://com.osa.mdsp.enabler.sei/SMSEnabler/V2_0/SMSSenderSEI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <x0:sms> <tns2:content>TEST</tns2:content> <tns2:recipient>501000508</tns2:recipient> </x0:sms> </x0:sendSMS>
Subject: Re: [rt.cpan.org #72616] XML::Compile - schema2example should generate vaild XML
Date: Wed, 23 Nov 2011 16:07:28 +0100
To: Piotr Roszatycki via RT <bug-XML-Compile [...] rt.cpan.org>
From: Mark Overmeer <secretaris [...] nluug.nl>
* Piotr Roszatycki via RT (bug-XML-Compile@rt.cpan.org) [111123 15:00]: Show quoted text
> Nice. But also I've found that nsxml:xsi is added also when this > namespace is not really used in XML document.
Did you try my implementation? I reworked it a little to only include the xs and xsi declarations when show_type was set. On the other hand: it is only an example, so a little bit of sloppiness is acceptable, I think. -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
The above example was called with XML::Compile 1.23. I thought it was regression but additional and unnecessary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" was included also in 1.21 and 1.22. I think this bugreport can be closed as far as schema2example emits correct XML file (of course for simple schemas). Thank you very much.
closed