Whats the best way to indicate which version of an

2019-05-30 07:28发布

问题:

I am asking this question predominantly in the context of a REST/XML web service API (media type "application/vnd.mystuff+xml"), but perhaps the question is still valid for SOAP based web services.

In the event that the XML schema that describes the vocabulary of our resources/payloads changes, how should I best indicate to the client they should use/expect a newer version of the XML schema?

Should we include a version identifier in the root element like this:

<mything xmlns="http://mycompany.com/yadda" version="1.0">

or should we just reference the XML schema like this:

<mything  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:SchemaLocation="http://mycompany.com/yadda/1 yadda-1.0.xsd"
          xmlns="http://mycompany.com/yadda">

or both?

<mything  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:SchemaLocation="http://mycompany.com/yadda/1 yadda-1.0.xsd"
          xmlns="http://mycompany.com/yadda"
          version="1.0">

Is it common practice to send an XML payload that references an XML schema?

回答1:

No. Use the XML namespace to specify which schema to use.