Customize XML serialization with WSName and XMLName

Use the WSName and XMLName attributes to customize serialization at runtime and improve the readability of the XML output.

Formatting XML output with WSName and XMLName

IMPORT com

TYPE profileType RECORD ... END RECORD
   
PUBLIC DEFINE myError RECORD ATTRIBUTE(WSError="My error")
  code INTEGER,
  reason STRING
END RECORD

PUBLIC FUNCTION getUsersList()
  ATTRIBUTES (WSGet, 
              WSPath="/users",
              WSDescription="Get list of users",
              WSThrows="400:Invalid,404:NotAvailable" )
  RETURNS (
    DYNAMIC ARRAY ATTRIBUTE(WSName="All_users_list",WSMedia="application/xml") OF profileType 
    ATTRIBUTE(XMLName="User")
    )
  
    DEFINE usersList DYNAMIC ARRAY OF profileType
    ... function code 
 
  RETURN usersList
END FUNCTION
The function returns the output in XML format as a string. The output contains the tags specified by the attributes.
  • The WSName attribute for the array gives <All_users_list> as the root tag for the output.
  • The XMLName attribute (XMLName="User") maps the BDL record (profileType) and tags each element with <User> in the XML document.
For example, when viewed in an XML viewer, it would display as shown.
<All_users_list>
  <User>
    ... record content
  </User>
  <User>
    ... record content
  </User>
  ...
</All_users_list>
Note: If you do not use the attributes, the names in the XML output are default names derived from DVM names, for example,"rv0", which may not be user-friendly.