Why is XML used in web services?

风格不统一 提交于 2019-12-02 08:47:54

XML has the potential to transfer self-descriptive data, and has a large following.

Plain text, or simple delimited files, tell you nothing about the data contained in the payload.

This makes it less desirable in cases where adequate domain knowledge cannot be assumed on the part of the web service consumer.

JSON is kind of a hybrid approach - more descriptive than plain text, or delimited files (I'm assuming you mean something like a CSV file), but less onerous to deal with, simpler for a human to read, and more elegant (in some opinions) than XML.

If you're looking for the "right" answer for your boss, well, there really isn't one. The standards for 'conversation' between a web service publisher and consumer depends on a whole host of factors - was the API decided before you came along? does the other side deal only with technology X? Any number of factors could have decided the data exchange format.

If you want REAL fun, try working with EDX trading partners - ugh.

Before XML there were lots of plain text formats for sending messages. Each was different, most of them were poorly specified, so it was never 100% clear what was allowed and what wasn't. People designing such formats ended up putting lots of effort into designing the syntax, leaving not enough time to go into designing the semantics. Anyone receiving data in such a format had to write their own parser. Most people aren't good at writing parsers (they skipped those lectures in their computer science education, or they never had a computer science education in the first place), so they did it badly and got it wrong.

So XML arrived and did away with all that. People designing messages could now concentrate on the semantics of the data rather than inventing yet another syntax. People writing code to read and write messages could use XML libraries "off the shelf" rather than hand-crafting their own. Schema languages were invented that allowed the validation code to be automated. High-level transformation and query languages were invented so you didn't have to grovel around the data in low-level procedural code.

And God saw that it was good. Well, Microsoft, Sun, Oracle, and IBM did, and that was good enough for most people.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!