Skip Menu |

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

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

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

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



Subject: Request: handle complexType/simple content nicer
The docs say: complexType/simpleContent In this case, the single value container may have attributes. The number of attributes can be endless, and the value is only one. This value has no name, and therefore gets a predefined name _. ยป Example: typical simpleContent example In XML, this looks like this: <test2 question="everything">42</test2> As a HASH, this looks like test2 => { _ => 42 , question => 'everything' } Therefore, I cannot simply do $write->($doc, { foo => 'bar' }); if the foo type has been declared as a complexType in the XSD - I need to pass { foo => { _ => 'bar }} instead. What would be really nice is if this translation happened automatically - i.e. in XML::Compile::Translate::Writer::makeComplexElement, instead of erroring with "complex {tag} requires a HASH of input data..." if !ref($data), instead it made the transformation to { $tag => { _ => $data }} itself.
Subject: Re: [rt.cpan.org #79270] Request: handle complexType/simple content nicer
Date: Tue, 28 Aug 2012 23:45:18 +0200
To: Karen Etheridge via RT <bug-XML-Compile-SOAP [...] rt.cpan.org>
From: Mark Overmeer <solutions [...] overmeer.net>
* Karen Etheridge via RT (bug-XML-Compile-SOAP@rt.cpan.org) [120828 21:39]: Show quoted text
> Tue Aug 28 17:38:51 2012: Request 79270 was acted upon. > Transaction: Ticket created by ETHER > Queue: XML-Compile-SOAP > Subject: Request: handle complexType/simple content nicer > > The docs say: > complexType/simpleContent > > Therefore, I cannot simply do $write->($doc, { foo => 'bar' }); if the > foo type has been declared as a complexType in the XSD - I need to pass > { foo => { _ => 'bar }} instead.
It may not in the docs, but it should work. Show quoted text
> What would be really nice is if this translation happened automatically > - i.e. in XML::Compile::Translate::Writer::makeComplexElement, instead > of erroring with "complex {tag} requires a HASH of input data..." if > !ref($data), instead it made the transformation to { $tag => { _ => > $data }} itself.
complexType/simpleContent is handled in makeTaggedElement, not makeComplexElement. It contains my $copy = UNIVERSAL::isa($data, 'HASH') ? {%$data} : {_ => $data}; So, something else may not be working as expected. Example code? -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
On Tue Aug 28 14:45:34 2012, solutions@overmeer.net wrote: Show quoted text
> complexType/simpleContent is handled in makeTaggedElement, not > makeComplexElement. It contains > > my $copy = UNIVERSAL::isa($data, 'HASH') ? {%$data} : {_ => $data}; > > So, something else may not be working as expected. Example code?
Attached is a sample XSD and demonstration code. When I run it, I get: error: complex `transaction_id' requires a HASH of input data, not `unique_id_here' at interface_name/transaction_id at /home/ad/karene/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/Log/Report/Dispatcher/Perl.pm line 29. Log::Report::Dispatcher::Perl::log('Log::Report::Dispatcher::Perl=HASH(0x32c63a0)', 'HASH(0x2f8d588)', 'ERROR', 'Log::Report::Message=HASH(0x32c6568)') called at /home/ad/karene/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/Log/Report.pm line 140 Log::Report::report('ERROR', 'Log::Report::Message=HASH(0x32c6568)') called at /home/ad/karene/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/Log/Report.pm line 277 Log::Report::error('Log::Report::Message=HASH(0x32c6568)') called at /home/ad/karene/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/XML/Compile/Translate/Writer.pm line 529 XML::Compile::Translate::Writer::__ANON__('XML::LibXML::Document=SCALAR(0x1adebe8)', 'unique_id_here') called at /home/ad/karene/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/XML/Compile/Translate/Writer.pm line 418 XML::Compile::Translate::Writer::__ANON__('XML::LibXML::Document=SCALAR(0x1adebe8)', 'unique_id_here') called at /home/ad/karene/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/XML/Compile/Translate/Writer.pm line 402 XML::Compile::Translate::Writer::__ANON__('XML::LibXML::Document=SCALAR(0x1adebe8)', 'unique_id_here') called at /home/ad/karene/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/XML/Compile/Translate/Writer.pm line 167 XML::Compile::Translate::Writer::__ANON__('XML::LibXML::Document=SCALAR(0x1adebe8)', 'HASH(0x1d71a70)') called at /home/ad/karene/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/XML/Compile/Translate/Writer.pm line 373 XML::Compile::Translate::Writer::__ANON__('XML::LibXML::Document=SCALAR(0x1adebe8)', 'HASH(0x1d71a70)') called at /home/ad/karene/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/XML/Compile/Translate/Writer.pm line 534 XML::Compile::Translate::Writer::__ANON__('XML::LibXML::Document=SCALAR(0x1adebe8)', 'HASH(0x1adeaf8)') called at /home/ad/karene/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/XML/Compile/Translate/Writer.pm line 418 XML::Compile::Translate::Writer::__ANON__('XML::LibXML::Document=SCALAR(0x1adebe8)', 'HASH(0x1adeaf8)') called at /home/ad/karene/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/XML/Compile/Translate/Writer.pm line 114 XML::Compile::Translate::Writer::__ANON__('XML::LibXML::Document=SCALAR(0x1adebe8)', 'HASH(0x1adeaf8)') called at rt79270.pl line 51
Subject: rt79270.pl
use strict; use warnings; use Carp::Always; use DateTime; use XML::Compile::Schema; use XML::Compile::Util 'pack_type'; use XML::LibXML; my $now = DateTime->now(time_zone => 'UTC'); my $data = { interface_name => { transaction_id => 'unique_id_here', Userid => '1234', UtcDateAndTime => { DayOfWeek => $now->day_name, DayOfMonth => sprintf('%02d', $now->day_of_month), Month => $now->month_abbr, Year => $now->year, Hour => sprintf('%02d', $now->hour), Minute => sprintf('%02d', $now->minute), Second => sprintf('%02d', $now->second), }, }, }; # this should be moved to the module_share dir my $schema = XML::Compile::Schema->new('complextype.xsd'); my $doc = XML::LibXML::Document->new('1.0', 'UTF-8'); my $write = $schema->compile( WRITER => pack_type('', 'interface_name'), ); my $xml = $write->($doc, # this only works if our XSD isn't insane: # - no mixed=true for simple types # - no complex types for the simple types $data->{interface_name}, ); $doc->setDocumentElement($xml); print "XML GENERATED:\n"; print $doc->toString(1);
Subject: complextype.xsd
Download complextype.xsd
application/xml 1.3k

Message body not shown because it is not plain text.

Subject: Re: [rt.cpan.org #79270] Request: handle complexType/simple content nicer
Date: Thu, 30 Aug 2012 19:20:52 +0200
To: Karen Etheridge via RT <bug-XML-Compile-SOAP [...] rt.cpan.org>
From: Mark Overmeer <mark [...] overmeer.net>
* Karen Etheridge via RT (bug-XML-Compile-SOAP@rt.cpan.org) [120830 15:57]: Show quoted text
> Queue: XML-Compile-SOAP > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=79270 > > > On Tue Aug 28 14:45:34 2012, solutions@overmeer.net wrote: >
> > complexType/simpleContent is handled in makeTaggedElement, not > > makeComplexElement. It contains > > > > my $copy = UNIVERSAL::isa($data, 'HASH') ? {%$data} : {_ => $data}; > > > > So, something else may not be working as expected. Example code?
> > Attached is a sample XSD and demonstration code. When I run it, I get: > > error: complex `transaction_id' requires a HASH of input data, not > `unique_id_here' at interface_name/transaction_id
The reported error is correct. There is only a valid case for complexType/simpleContent structures to translate <xyz abc="42">13</xyz> into xyz => {abc => 42, _ => 13} and to allow xyz => 17 as alternative for xyz => { _ => 17 } For other complexType structures (simple complexType and complexType/- complexContent) this is impossible to implement. Why do you expect that to work in the first place? I even do not see a use-case. An empty complex can be specified as: transaction_id => {} which differs from transaction_id => undef The latter will not produce anything, the former <transaction_id/> Also weird to see a complex UtcDateAndTime structure, where we have such a nice iso standard dataTime type in schema's. Although I have encountered such before. -- 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 #79270] Request: handle complexType/simple content nicer
Date: Thu, 30 Aug 2012 11:27:55 -0700
To: Mark Overmeer via RT <bug-XML-Compile-SOAP [...] rt.cpan.org>
From: Karen Etheridge <ether [...] cpan.org>
Show quoted text
> There is only a valid case for complexType/simpleContent structures > to translate <xyz abc="42">13</xyz> into xyz => {abc => 42, _ => 13} > and to allow xyz => 17 as alternative for xyz => { _ => 17 }
Isn't the latter - translating xyz => 17 into xyz => { _ => 17 } exactly the transformation I described at the beginning of this ticket? I'll pop on #xml-compile... Show quoted text
> Also weird to see a complex UtcDateAndTime structure, where we have > such a nice iso standard dataTime type in schema's. Although I have > encountered such before.
I've given up trying to understand the insanity I see in schemas... so much fail... :/ For example, is it even correct for the schema to specify these fields as complex types, when they are only ever going to be passed strings?
Subject: Re: [rt.cpan.org #79270] Request: handle complexType/simple content nicer
Date: Thu, 30 Aug 2012 20:37:11 +0200
To: Karen Etheridge via RT <bug-XML-Compile-SOAP [...] rt.cpan.org>
From: Mark Overmeer <website [...] craneveer.nl>
* Karen Etheridge via RT (bug-XML-Compile-SOAP@rt.cpan.org) [120830 18:28]: Show quoted text
> Queue: XML-Compile-SOAP > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=79270 > >
> > There is only a valid case for complexType/simpleContent structures > > to translate <xyz abc="42">13</xyz> into xyz => {abc => 42, _ => 13} > > and to allow xyz => 17 as alternative for xyz => { _ => 17 }
> > Isn't the latter - translating xyz => 17 into xyz => { _ => 17 } > exactly the transformation I described at the beginning of this ticket?
Yes, you found that in the man-page. You want to use that transformation on something where it cannot be used for, as I have explained twice by now. Show quoted text
> I'll pop on #xml-compile...
You you think that will change my answer? Show quoted text
> I've given up trying to understand the insanity I see in schemas...
Most schema's contain some bugs. Like most programmers, many schema developers also do not understand/know all options. Some tools do help them making the right decissions, usually not. Show quoted text
> For example, is it even correct for the schema to specify these > fields as complex types, when they are only ever going to be passed > strings?
Only if they are "mixed", which means "free format". -- 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 #79270] Request: handle complexType/simple content nicer
Date: Thu, 30 Aug 2012 12:02:51 -0700
To: Mark Overmeer via RT <bug-XML-Compile-SOAP [...] rt.cpan.org>
From: Karen Etheridge <ether [...] cpan.org>
On Thu, Aug 30, 2012 at 02:37:25PM -0400, Mark Overmeer via RT wrote: Show quoted text
> > Isn't the latter - translating xyz => 17 into xyz => { _ => 17 } > > exactly the transformation I described at the beginning of this ticket?
> > Yes, you found that in the man-page. You want to use that transformation > on something where it cannot be used for, as I have explained twice by > now. >
> > I'll pop on #xml-compile...
> > You you think that will change my answer?
I'm not trying to argue with you, I'm trying to understand what you're saying. Show quoted text
> > For example, is it even correct for the schema to specify these > > fields as complex types, when they are only ever going to be passed > > strings?
> > Only if they are "mixed", which means "free format".
What about the UtcDateAndTime field? it's complex (a nested hash), but it cannot be free-format - it must have the specified fields nested in it.
Subject: Re: [rt.cpan.org #79270] Request: handle complexType/simple content nicer
Date: Thu, 30 Aug 2012 21:49:22 +0200
To: Karen Etheridge via RT <bug-XML-Compile-SOAP [...] rt.cpan.org>
From: Mark Overmeer <website [...] craneveer.nl>
* Karen Etheridge via RT (bug-XML-Compile-SOAP@rt.cpan.org) [120830 19:03]: Show quoted text
> > You you think that will change my answer?
> I'm not trying to argue with you, I'm trying to understand what you're > saying.
Second part of the attached slides may help you understanding it better. Show quoted text
> What about the UtcDateAndTime field? it's complex (a nested hash), but it > cannot be free-format - it must have the specified fields nested in it.
It is not a field but a container (complexType). Containers are either complexContent (with nested elements), simpleContent (single value), or mixed. -- Regards, MarkOv ------------------------------------------------------------------------ Mark Overmeer MSc MARKOV Solutions Mark@Overmeer.net solutions@overmeer.net http://Mark.Overmeer.net http://solutions.overmeer.net
Download xml.odp
application/vnd.oasis.opendocument.presentation 3m

Message body not shown because it is not plain text.

cannot be implemented