0

In an XML SOAP is the soapenv keyword mandatory or can it be replaced with something else. For example:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>

Could I replace this with

<ans1:Envelope xmlns:ans1="http://schemas.xmlsoap.org/soap/envelope/">
    <ans1:body>
Mojo
  • 1,152
  • 1
  • 8
  • 16

1 Answers1

1

Yes, both of those XML requests should be treated as equivalent by any properly implemented SOAP parser.

The "soapenv" is not a keyword, and is not standardised anywhere; indeed, variants such as "SOAP", "ENV", "SOAP-ENV", etc are equally common in my experience. It would also be possible not to have a prefix there at all:

<Envelope xmlns"http://schemas.xmlsoap.org/soap/envelope/">
    <body>
    </body>
</Envelope>

The mechanism involved here is "XML namespaces", which allow XML elements and attributes with the same name from different standards to be mixed in one document.

The central idea is that each element and attribute is associated with a namespace URI - the URI doesn't have to point anywhere, and is not requested by the parser, it's just a way of someone "owning" the namespace. In this case, the namespace URI is http://schemas.xmlsoap.org/soap/envelope/ and that is the part that must be present in every SOAP request and response.

However, rather than repeating that URI on every element, XML namespaces are either associated with a local prefix or marked as the default namespace for a particular set of elements.

The local prefix can be absolutely anything, and is defined inline in the document with the syntax xmlns:prefix="uri" - in this case, xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" just means "associate the prefix soapenv with the namespace http://schemas.xmlsoap.org/soap/envelope/ for this part of the document". Elements and attributes can then be prefixed with soapenv: (or whatever you choose) to associate them to that namespace.

The default namespace is specified with xmlns="uri", so xmlns="http://schemas.xmlsoap.org/soap/envelope/" means "treat all un-prefixed elements as in the http://schemas.xmlsoap.org/soap/envelope/ namespace for this part of the document". Slightly oddly, the default namespace doesn't apply to attributes.

IMSoP
  • 89,526
  • 13
  • 117
  • 169