On Tue, Sep 10, 2013 at 12:57:38PM +0200, Mark Overmeer wrote:
> * Alex Bernier ([email protected]) [130910 10:40]:
> > On Tue, Sep 10, 2013 at 12:11:09PM +0200, Mark Overmeer wrote:
> > > The attached script demonstrates that it works when your data-structure
> > > is correct. You forgot the cho_multipleChoiceQuestion level.
> > 
> > Thank you very much.
> > 
> > Regarding the syntax : I don't understand clearly why the
> > "inputQuestion" elements should be included in a variable called
> > "cho_multipleChoiceQuestion". Why "cho_inputQuestion => \@questions"
> > produces invalid code ?
> 
> You should not (try to) think ;-)   $wsdl->template(PERL => $type)
> produces what is expected, and you should follow that.
> 
> The problem is your nested <choice> does not have a name.  The XML
> structure can not be mapped to a perl structure without a name, so
> X::C constructs a name based on the first element inside the choice.
> multipleChoiceQuestion is the name of the first element, hence
> cho_multipleChoiceQuestion is the name of the choice block.  Even
> if you only put other elements in there.

Thanks !

> 
> > Another question : which syntax should I use to produce output like
> > <do:label xml:lang="en"> instead of <do:label lang="en"> ?
> 
> When you use a schema, you use schema data-types, so I do not expect
> to see xml:lang where we have an xsd:language type.  However, it is
> possible...  I see this:
> 
>   <xs:element name="label">
>     <xs:complexType>
>       <xs:sequence>
>         ...
>       </xs:sequence>
>       <xs:attribute ref="xml:lang" use="required"/>
> 
> So, you "lang" parameter will get taken.  Whether the attribute is
> included as 'lang' or 'xml:lang' depends on the attributeFormDefault
> of the schema.
> 
> Your xml.xsd does not say attributeFormDefault="qualified", so it
> defaults to "unqualified".  Old schema's often do not have these
> *FromDefault lines in them, because they were added as syntax later.
> You can fix that when loading the schema:
> 
>   $wsdl->importDefinitions('xml.xsd'
>     , attribute_form_default => 'qualified'
>     );

I patched the line (see attached file) but still get lang="en" and not 
xml:lang="en" as output. Did I miss something ?

Regards,

Alex
#!/usr/bin/env perl
use XML::Compile::WSDL11;
use XML::LibXML;
use Log::Report mode => 3;

my $wsdl = XML::Compile::WSDL11->new
  ( 'do-wsdl-10.wsdl'
  , prefixes => [do => 'http://www.daisy.org/ns/daisy-online/' ]
  );

# $wsdl->importDefinitions([glob "*.xsd"]);
$wsdl->importDefinitions('do-types-10.xsd');
$wsdl->importDefinitions('xml.xsd',{ attribute_form_default => 'qualified'});
$wsdl->importDefinitions('dc.xsd');
$wsdl->importDefinitions('bookmark-2005-1.xsd');
$wsdl->importDefinitions('KeyExchange-2005-1.xsd');
$wsdl->importDefinitions('xenc-schema.xsd');
$wsdl->importDefinitions('xmldsig-core-schema.xsd');

print $wsdl->template(PERL => 'do:getQuestionsResponse');

my @questions;
push @questions,
  +{ inputQuestion =>
      { id=>'q1'
      , inputTypes => { input => { type => 'TEXT_ALPHANUMERIC' } }
      , label => { lang=>'en', text => 'Choice 1' }
   }  };

push @questions,
  +{ inputQuestion =>
      { id=>'q2'
      , inputTypes => { input => { type => 'TEXT_ALPHANUMERIC' } }
      , label => { lang=>'en', text => "Choice 2" }
   }  };

my $data = +{ questions => { cho_multipleChoiceQuestion => \@questions } };

my $doc  = XML::LibXML::Document->new('1.0', 'UTF-8');

my $xml  = $wsdl->writer('do:getQuestionsResponse')->($doc, $data);
print $xml->toString(1);

_______________________________________________
Xml-compile mailing list
[email protected]
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/xml-compile

Reply via email to