为什么在 Web 服务中使用 XML? [英] Why is XML used in web services?

查看:24
本文介绍了为什么在 Web 服务中使用 XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次编写需要与其他程序通信的程序,使用 Web 服务,特别是 SOAP V1.2 和 HTTP 协议.我的雇主一直问我三件事,我真的无法回答:

I am, for the first time, writing a program in which needs to communicate with other programs, using web services, specifically the SOAP V1.2 and HTTP protocols. My employer keep asking me three things that I can't really answer:

  • 为什么使用 XML 作为信息交换的约定 (W3C)?
  • 例如,为什么他们不能使用纯文本或分隔文件?

为什么要使用重复的、重标签的语言来交换信息?好的纯文本怎么了?

Why use a repetitive heavy tag-based language to exchange info? What happened to the good ol' plain text?

推荐答案

在 XML 出现之前,有很多用于发送消息的纯文本格式.每个都是不同的,大多数都没有明确规定,所以从来没有 100% 清楚什么是允许的,什么是不允许的.设计这种格式的人最终在设计语法上投入了大量精力,没有足够的时间来设计语义.任何以这种格式接收数据的人都必须编写自己的解析器.大多数人不擅长编写解析器(他们在计算机科学教育中跳过了那些讲座,或者他们一开始就没有接受过计算机科学教育),所以他们写得不好,而且弄错了.

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.

因此 XML 出现并消除了所有这些.设计消息的人们现在可以专注于数据的语义,而不是发明另一种语法.编写代码来读写消息的人可以使用现成的"XML 库,而不是自己手工制作.发明了允许验证代码自动化的模式语言.发明了高级转换和查询语言,因此您不必在低级程序代码中处理数据.

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.

上帝认为这很好.嗯,微软、Sun、甲骨文和 IBM 做到了,这对大多数人来说已经足够了.

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

这篇关于为什么在 Web 服务中使用 XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆