Menu

#1306 Namespace prefix attached in xsi:type value even for SOAP_XML_DEFAULTNS

v1.0 (example)
closed-fixed
2
2023-03-21
2022-08-29
Suyog Jain
No

In version - 2.8.17
We are using Amazon.xsd for testing complex attribute with inheritance. And earlier we used to receive

     <Grantee xsi:type="CanonicalUser">
            <ID>sample</ID>
            <DisplayName>sample</DisplayName>
        </Grantee>

But after upgrading to version 2.8.108 -

In version - 2.8.108, additional namespace prefix("s3:") is attached to "CanonicalUser"

     <Grantee xsi:type="s3:CanonicalUser">
            <ID>sample</ID>
            <DisplayName>sample</DisplayName>
        </Grantee>

The reason for this is the code which was removed from stdsoap2.cpp. That was present in 2.8.17 version before line - "if (soap_attribute(soap, "xsi:type", type))"

ifndef WITH_LEAN

if (soap->mode & SOAP_XML_DEFAULTNS)
{ s = strchr(type, ':');
  if (s)
    s++;
  else
    s = type;
}

Expectation is the for flag - SOAP_XML_DEFAULTNS, the xsi:type should return "CanonicalUser", rather it returns "s3:CanonicalUser". Is there any way we can preserve behavior of the older version?

Discussion

  • Robert van Engelen

    The old code was changed/removed after 2.8.17 because it triggered a bug with the SOAP_XML_DEFAULT flag. The code is insufficient. Note that xsi:type is only useful for cases that require inheritance, i.e. to distinguish the base from a derived type. Newer gsoap versiosn do not use xsi:type by default any longer, only to disambiguate base/derived types.

     
  • Robert van Engelen

    Let me explain why the old code fails. Consider:

    <xx:name xsi:type="xsd:string">
    

    without prefixes this should be:

    <name xmlns="some-uri" xsi:type="xsd:string">
    

    It is not correct to remove the prefix from the xsi:type, but only when the prefix matches the current default namespace of course. Now, normally we don't see any xsi:type attributes like this any longer.

    A better solution might be to make the following change to soap_element():

        if ((soap->mode & SOAP_XML_DEFAULTNS))
        {
          size_t n = 0;
          s = strchr(tag, ':');
          if (s)
          {
            n = s++ - tag;
            if (type && !strncmp(type, tag, n + 1))
              type += n + 1;
          }
          else
          {
            s = tag;
          }
    
     
  • Robert van Engelen

    • status: open --> pending-fixed
     
  • Robert van Engelen

    Upcoming gsoap 2.8.127 has the code update suggested above.

     
  • Robert van Engelen

    • status: pending-fixed --> closed-fixed
     

Log in to post a comment.