Search code examples
xmlsms

Which XML structure is best suited for an all round API?


Please advise if you can.

I am building an SMS web service API that will allow people to send SMS to their desired cellphone numbers. A request will be sent to the interface, we then process that request based on the account details provided and credits available on their account.

We have two proposed XML structures for the interface request and I would like you to advise which one is better as we are going at each others throats about it.

Interface A

print("<?xml version = "1.0" encoding="UTF-8" standalone="yes"?>
        <Message version="1.0">
            <ClientID>11111</ClientID>
            <PassPhrase>shjfkh</PassPhrase>
            <Request Type="sms" Refno="10" ToAddress="27732687745332">
                <Content>
                      hello world
                </Content>
            </Request>
        </Message> ");

Interface B

 print("<?xml version = "1.0" encoding="UTF-8" standalone="yes"?>
    <Message>
        <mmtag name="Version">1.0</mmtag>
        <mmtag name="ClientID">1001</mmtag>
        <mmtag name="RefNO">120</mmtag>
        <mmtag name="Encoding">base64</mmtag>
        <mmtag name="Type">SMS</mmtag>
        <mmtag name="Content">hello world</mmtag>
        <mmtag name="MSISDN">27781010102</mmtag>        
    </Message>");

Now, looking at the two examples, which do you think would be best-suited for our API interface, regardless of the technology in the back end. Please support your answer should you pick one.


Solution

  • Interface A.

    Interface B is essentially just a list of key/values, where as Interface A takes advantage of the structured nature of XML and provides meaning through the structure.

    For example: ClientId is an attribute of the Message, not the Request itself. This is clear from looking at A, but not from B.