xsd模式可以验证编码,例如UTF-8,可能吗? [英] can xsd schema validate encoding, e.g. UTF-8, possible?

查看:161
本文介绍了xsd模式可以验证编码,例如UTF-8,可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过使用模式,是否有任何简单/简便的方法来验证xml msg的编码?

By using schema, is there any simple/easy way to validate the encoding of an xml msg?

假设xml的第一行不"可信赖? 例如忽略?xml version ="1.0" encoding ="UTF-8"吗?

Assuming the 1st line of xml is "not" trustworthy? e.g. ignore ?xml version="1.0" encoding="UTF-8" ?

推荐答案

否,除了二进制数据元素类型以外,模式无法决定编码类型,但是该编码仍将由高级编码封装文档本身.如果您意识到该架构是用来描述信息而不是传输格式的,那么这是有道理的. XML规范决定了文档传输信息,例如如何以最广义的方式表示和存储信息.模式用于验证通过XML存储的数据是否符合各方之间的某种语法约束. XML规范中定义的序言(您提到的第一行)是一个实体,在该实体中,存在性(或不存在)是投诉XML读者需要知道如何对文档进行编码的实体.编码只是端点之间代表正确的unicode代码点的协议,而XML规范指定了如何达成此协议,而不是模式.

No, schema can't dictate encoding type except in terms of the binary data element types, but this encoding is still going to be encapsulated by the high level encoding of the document itself. This makes sense if you realize that the schema is suppose to describe the information and not the transport format. The XML specification is what dictates that document transport information such as how information is represented and stored in the most generalized sense. Schema is for validating that the data stored via XML meets some kind of syntactical restraints between parties. The prolog (that first line you mention) as defined in the XML spec is the entity in which existence (or not) is what a complaint XML reader needs to know how the document is encoded. Encoding is simply the agreement between the endpoints to represent the correct unicode code points and XML specification specifies how this agreement is reached, not schema.

如果您有兴趣,这是XML 1.1规范中有关如何达成此协议的相关部分,更有趣的是投诉读者如何猜测"编码,因此可以很好地猜测序言可以读取以读取实际的编码属性: http://www.w3.org/TR/xml11/#sec-guessing

If you are interested, this is the relevant section of the XML 1.1 specification on how this agreement is reached and more interesting how a complaint reader can 'guess' at the encoding so it is good enough of a guess that the prolog can be read to read the actual encoding attribute: http://www.w3.org/TR/xml11/#sec-guessing

这篇关于xsd模式可以验证编码,例如UTF-8,可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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