XML Schema Header & Namespace Config

后端 未结 3 1352
执笔经年
执笔经年 2020-12-23 22:54

Migrating from DTD to XSD and for some reason the transition is a bumpy one. I understand how to define the schema once I\'m inside the root t

3条回答
  •  时光取名叫无心
    2020-12-23 23:20

    In answer to your queries:

    1. xmlns - a unique value used in instance documents to indicate which schema the XML is an instance of (or what schema it will validate against). Even though the namespace does not identify the actual schema file, there should be one schema which defines this namespace.
    2. xmlns:xs - called namespace prefixes and by convention used in instance documents to indicate where the types used in the XML are coming from. You can think of this like using in C# or imports in VB. For example, xmlns:xs="http://mySharedTypes" says that in this XML some of my types come from the namespace "http://mySharedTypes", and these types will be prefixed with "xs".
    3. xmlns:xsi - as above. Infact the xs and xsi prefixes are by convention used when referencing the W3C schema namespaces http://www.w3.org/2001/XMLSchema and http://www.w3.org/2001/XMLSchema-instance. However these namespace prefixes are just convention and can actually be anything.
    4. targetNamespace - a unique value you put in your schema definition which gives the types you define in the schema their namespace. So if someone wants to use the types in your schema then they must include an xmlns attribute with the same values as your targetNamespace.
    5. xs:import schemaLocation - This is conventionally a relative path to another schema, although not all xml processors recognise it. So you can optionally link to another schema in your xs:import as a kind of shortcut to the schema file itself. The other attribute in the import is the schema targetNamespace, which is mandatory.
    6. xsi:schemaLocation - Although this shares the same name as the import attribute it is not the same definition. By convention, the xsi namespace prefix refers to types from the http://www.w3.org/2001/XMLSchema-instance namespace, which are used inside instance documents, rather than schema documents.

    Sorry if the above is not clear, it's a little bit of an open-ended question and there is a ton of material you could write for any one of these points. If you need clarity on any of the points please ask - I will be happy to provide, or alternatively create a new question with narrower scope.

提交回复
热议问题