WSO2Con 2013 CFP Banner

How to specify an xml:lang attribute in WSDL mode

johan's picture

Hi,

I'm developing a service in PHP using wsdl mode and can't figure out how to specify an xml:lang attribute in order to receive the exepcted response below. I use the code wsdl2php code generator to generate the service base on the WSDL file.

The types schema in the WSDl file

<xs:schema targetNamespace="http://www.daisy.org/ns/daisy-online/" elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2009/01/xml.xsd"/>
  <xs:element name="logOn">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="1" name="username" type="xs:string"/>
        <xs:element minOccurs="1" maxOccurs="1" name="password" type="xs:string"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="logOnResponse">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="1" name="logOnResult" type="xs:boolean"/>
        <xs:element minOccurs="0" maxOccurs="1" name="label" type="tns:label"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:complexType name="label">
    <xs:sequence>
      <xs:element minOccurs="1" maxOccurs="1" name="text" type="xs:string"/>
    </xs:sequence>
    <xs:attribute use="optional" ref="xml:lang"/>
  </xs:complexType>
</xs:schema>

Generated code for the label class

class label {

  /*
   * @var string
   */
  public $text;

  /*
   * @var language
   *   NOTE: lang should follow the following restrictions
   */
  public $lang

}

Received response

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header/>
  <soapenv:Body>
    <ns1:logOnResponse xmlns:ns1="http://www.daisy.org/ns/daisy-online/" xmlns:ns2="http://www.w3.org/XML/1998/namespace">
      <ns1:logOnResult>true</ns1:logOnResult>
      <ns1:label ns2:lang="en">
        <ns1:text>Some text</ns1:text>
      </ns1:label>
    </ns1:logOnResponse>
  </soapenv:Body>
</soapenv:Envelope>

Expected response

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header/>
  <soapenv:Body>
    <ns1:logOnResponse xmlns:ns1="http://www.daisy.org/ns/daisy-online/" xmlns:xml="http://www.w3.org/XML/1998/namespace">
      <ns1:logOnResult>true</ns1:logOnResult>
      <ns1:label xml:lang="en">
        <ns1:text>Some text</ns1:text>
      </ns1:label>
    </ns1:logOnResponse>
  </soapenv:Body>
</soapenv:Envelope>

According to http://www.w3.org/XML/1998/namespace, the prefix is bound to xml: whenever the namespace "http://www.w3.org/XML/1998/namespace" is used.

//Johan

nandika's picture

Re

This is a bug in the code. Please raise a jira for this issue. Regards Nandika