can xsd schema validate encoding, e.g. UTF-8, possible?

前端 未结 1 1059
执念已碎
执念已碎 2021-01-19 16:00

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

Assuming the 1st line of xml is \"not\" trustworthy? e.g. ignore ?xml version=\

1条回答
  •  野的像风
    2021-01-19 16:50

    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.

    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

    0 讨论(0)
提交回复
热议问题