XSD Validation for Web Services

Thoughts By 6 years ago

I am currently a uni student, and I have to admit that I find most of the classes a waste of time. I often find myself being taught what I consider to be redundant technology practices when more superior ones are being used by the industry. Having said that, it turns out I’m not always right. One of my classes was on XML’s use for database and web services, and one of the first techniques taught to us was XSD (AKA XML Schemas). As I was doing this I was thinking “XML to define XML… this is just ridiculous”, but eventually after giving a go, I was pleasantly surprised by some of its uses, so much so that I am now attempting to use in practice.

One of the apps I have been working on lately has had a lack of communication between the developers of the web service and the developers of the iOS client that feeds on the web service. Such miscommunication can lead to many frustrated hours of debugging. With XSD validation on both the web service as it is going out of the server and coming into the client gives the client confidence that the XML is formatted exactly the way it should be. Now I am not sure if there is an equivalent for JSON, if there is I would recommend you use that because JSON seems to be becoming the standard these days, and I’ll admit XML web services are becoming older technology.

XSD isn’t just good for validation though. If you were around at the start of the century you would be familiar with the direction web services were heading with technologies such as SOAP and WSDL, where code generation would rein supreme. Using just an XSD, we can turn XML strings into C++ traversal objects, using libraries such as CodeSynthesis┬áto completely automate the parsing of XML files (although we at B2Cloud won’t be using it as we cannot adhere to the GPL on commercial products, but I am sure there are plenty of other alternatives).

Compared to the way I used to handle web services using the NSXMLParser this way offers much better compatibility and reliability. Whenever I have to use or design an XML web service, from now on I will be using XSD to assist me.

  • I find with the right tools, XML is a pleasure to work with, and as you’ve described above it’s bullet proof when you’re exchanging between third parties. Message structure has to be validated and errors reported. Every major vendor has an XML stack with full validation support – there’s no excuse. JSON on the other hand .. there’s http://json-schema.org/ and https://github.com/kriszyp/json-schema but good luck – I’ve never had any! old = crusty = me, but also = mature & stable = works! ha!

  • josh

    Simon you are spot on, I never liked xml to start with but its versatility has grown on me and after I statred using an xml editor (http://www.liquid-technologies.com/xml-editor.aspx) my coding speed grew even faster.