Genivia Home Documentation
XML namespace tables

updated Mon Apr 22 2024 by Robert van Engelen
 
XML namespace tables

This module defines the Namespace XML namespace structure and function to activate a table. More...

Classes

struct  Namespace
 Structure of each row in a namespace table. More...
 

Functions

int soap_set_namespaces (struct soap *soap, const struct Namespace *namespaces)
 Activates an XML namespace table to generate and resolve xmlns namespace prefixes in XML messages. More...
 

Variables

struct Namespace namespaces []
 The global XML namespaces table with entries defined by the Namespace structure and populated in an .nsmap file generated by soapcpp2. More...
 

Detailed Description

This module defines the Namespace XML namespace structure and function to activate a table.

Function Documentation

int soap_set_namespaces ( struct soap soap,
const struct Namespace namespaces 
)

Activates an XML namespace table to generate and resolve xmlns namespace prefixes in XML messages.

This function sets the XML namespace table to be used by the engine to generate and resolve xmlns namespace prefixes in XML messages. Different tables can be set at any time, depending on the XML messaging requirements. However, XML generation and parsing may fail if prefix-URI bindings are missing in the table. Tables are generated by soapcpp2 in .nsmap files, which defines a global table namespaces that is used by default by the engines, but can be replaced by the XML namespace table specified with this function. Returns SOAP_OK or a soap_status error code.

Example:
#include "soapH.h"
struct Namespace my_namespaces[] = {
{ "SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", "http://www.w3.org/*soap-envelope", NULL },
{ "SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/", "http://www.w3.org/*soap-encoding", NULL },
{ "xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/*XMLSchema-instance", NULL },
{ "xsd", "http://www.w3.org/2001/XMLSchema", "http://www.w3.org/*XMLSchema", NULL },
{ "ns", "http://tempuri.org/ns.xsd", NULL, NULL },
{ NULL, NULL, NULL, NULL }
};
struct soap *soap = soap_new();
soap_set_namespaces(soap, my_namespaces); // use a specific XML namespace binding table for the next call
if (soap_call_ns__webmethod(soap, endpoint, NULL, ...))
{
soap_print_fault(soap, stderr);
}
else
{
...
}
soap_set_namespaces(soap, namespaces); // use the default XML namespace binding table, when defined, for the next call

This example defines SOAP 1.1 namespaces (SOAP-ENV and SOAP-ENC) to be used by default, but also accepts SOAP 1.2 because of the second URI in the third column. XML schema instance namespace xsi is used with xsi:type and xsi:nil and the XML schema namespace xsd is used with XSD types such as xsd:string, which may be used in XML messages. URI patterns in the third column may contain wildcard strings * and wildcard characters -.

Returns
SOAP_OK or a soap_status error code
Parameters
soapsoap context
namespacesthe XML namespace table to activate

Variable Documentation

struct Namespace namespaces[]

The global XML namespaces table with entries defined by the Namespace structure and populated in an .nsmap file generated by soapcpp2.

This XML namespaces table defines XML namespace prefix-URI pairs for XML generation, parsing and validation. The last row in the table must be followed by a row with a NULL value to indicate the end of the table. The requirement to link this global table can be removed at compile time with WITH_NONAMESPACES.