【1】基础 【2】schema 示例 【3】schema 校验 【4】xsd 位置
【1】基础
#xmlns 命名空间的语法 xmlns:namespace-prefix="namespaceURI" #targetNamespace 该属性声明了本XML Schema文档中定义的元素是属于targetNamespace属性指定的命名空间(URI)下的。 可以将默认命名空间xmlns和targetNamespace给定不一样的值,用另外加了前缀的命名空间引用targetNamespace的命名空间下的元素,这样在使用targetNamespace下定义的元素时需要加上该前缀: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.org/other" targetNamespace="http://www.example.org/book" xmlns:bo="http://www.example.org/book" elementFormDefault="qualified"> <xs:element name="books" type="bo:booksType"/><!-- 使用了bo前缀 --> <xs:complexType name="booksType"> ... #xsi:schemaLocation 其语法是:schemaLocation=“{namespaceURI} {xsd名称}”,前缀xsi是自定义的,不过现在大家都习惯了这个官方的习惯。其作用是告知解析器,schemaLocation指定的命名空间下的元素要用该xsd的schema来约束。