[Download] | [Documentation Home] | [Release Note]

Namespace Handling

Introduction

A data service is also a typical web service, with some added specialized functionality. So when talking about a web service, namespace handling is a crucial requirement, as every aspect is based on XML. In this section, we will show how WSO2 Data Services Server handles namespaces, from how the service namespace is set, to having multiple namespaces inside a complex result.

Service Namespace

The service namespace is the namespace that is used to unique identify a web service uniquely. In the WSDL which represents the service, it will be indicated with the "targetNamespace" attribute of the WSDL document element. The service namespace is set in the first step of the data services wizard. Figure 1 shows an example on how this is done.


Figure 1: Setting the service namespace.

Data Service Result Row Namespace

This namespace is set by setting the "Row namespace" value in the query result section. This namespace basically associates the result rows or result entries a specific namespace. So all the subelements in that result raw will be under this namespace by default. Figure 2 shows how the row namespace is set for the query result element "customers".


Figure 2: Setting the service row namespace.

After setting the row namespace, the element "customers"'s datatype falls under the given namespace, the XML Schema fragment in data types section taken from the service's WSDL is shown in Figure 3.


Figure 3: XML Schema type definition of the "customers" element with the given namespace.

Setting Namespaces for Specific Elements in the Result

We may get the requirement that, only some of the elements in the result row should contain a specific namespace. This can be done by setting the namespace in the output mappings. Figure 4 shows how it is done.


Figure 4: Setting a namespace for a single element in a result row.

Figure 5 shows how this is reflected in the WSDL.


Figure 5: WSDL of a data service with a specific namespace assigned to the "country" element.

Setting Namespaces for Complex Results

In complex results in data services, result elements can be arbitrarily nested. These nested elements can have their own namespaces. Figure 6 shows how this is represented in a dbs file fragment, which has a complex result.


Figure 6: Data service configuration with namespace assigned to a nested element.

The WSDL created for the above service is shown in Figure 7.


Figure 7: Data service WSDL with namespaces provided to a complex result.

Finally, when this service is executed, the resulted XML is shown below in Figure 8.


Figure 8: Data service result with complex types.

Namespace Inheritance in a Data Service

There are several places in a data service where you will define namespaces. And there's an inheritance order, where a top level defined namespace will be inherited by its children. The below list summarizes the inheritance order.

  1. Service namespace will be applied to all the aspects of the data service, i.e. results
  2. Result row namespace will override the service namespace and apply the given namespace for the whole result
  3. Complex result, nested elements will override the result row namespace and it will assign the namespace to all its child elements
  4. A namespace specifically assigned to an element will override the parent elements namespace and assign the given namespace to itself