Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
attila_mikulan
Employee
Employee

In this post I'd like to explain, how namespaces work in SOAP requests and responses. A typical error when calling webservices, is that the external partner (either provider, or consumer of a SAP service) doesn't send the SOAP XML with elements in proper namespaces. The reason is usually the lack of usage of namespace prefixes. SAP ABAP Web service framework always generates XMLs with qualified namespaces, which is the recommended way by W3C.

What is qualified and unqualified?

In this example (source: w3schools.org -> XML schema Element), the schema components (element name, type) in the http://www.w3.org/2001/XMLSchema namespace are unqualified and those for http://www.w3schools.com/w3schoolsschema (mystring) are qualified with the wsc prefix:


<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:wsc="http://www.w3schools.com/w3shoolsschema">
<element name="fname" type="wsc:mystring" />
</schema>


The major difference

If there is a namespace declaration anywhere in the XML file, it is available for that element and all elements in its child tree.

Unqualified: If you declare a namespace without using a prefix (unqualified), the default namespace is changed. This means, that all elements without a namespace prefix will be in that specific namespace in the child tree of that element.

Qualified: When using qualified namespace declaration, you define a namespace prefix (like a reference) and only those elements will be in that namespace, that have the specified prefix. The default namespace is not changed, therefore elements without prefixes remain in empty namespace.

Example

Case 1: Using prefixes (qualified namespaces)



<ns1:Calculator xmlns:ns1="calc:test:namespace">
<Input>2</Input>
<Operation>squareroot</Operation>
</ns1:Calculator>



Here only Calculator is in the "calc:test:namespace" namespace, with the prefix 'ns1'. Input and Operation are in empty namespace.

Case 2: No prefixes (unqualified namespaces)


<Calculator xmlns="calc:test:namespace">
<Input>2</Input>
<Operation>squareroot</Operation>
</Calculator>



In this example all elements are in the "calc:test:namespace" namespace, including Calculator, Input and Operation. The reason, is that the default namespace has been changed by the unqualified namespace declaration for all child elements as well. Therefore elements without prefix are also in this namespace.


Without using prefixes, the empty namespace should be declared to all child elements to make it equal to the previous case. Here is how:


<Calculator xmlns="calc:test:namespace">
<Input xmlns="">2</Input>
<Operation xmlns="">squareroot</Operation>
</Calculator>


1 Comment