加入收藏 | 设为首页 | 会员中心 | 我要投稿 大连站长网 (https://www.0411zz.cn/)- 文字识别、智能机器人、智能内容、自然语言处理、图像分析!
当前位置: 首页 > 运营中心 > 网站设计 > 教程 > 正文

XSD语法介绍

发布时间:2023-12-23 11:01:43 所属栏目:教程 来源:DaWei
导读: XML XSD保存在单独的文档中,文档可以链接到XML文档以使用它。

语法
XSD的基本语法如下 -
<?xml version = 1.0?>
<xs:schema xmlns:xs = http://www.w3.org/2001/XMLSchema>
targ
XML XSD保存在单独的文档中,文档可以链接到XML文档以使用它。

语法
XSD的基本语法如下 -
<?xml version = 1.0?>
<xs:schema xmlns:xs = http://www.w3.org/2001/XMLSchema>
   targetNamespace = http://www.jb51.cc
   xmlns = http://www.jb51.cc elementFormDefault = qualified>
   <xs:element name = 'class'>
      <xs:complexType>
         <xs:sequence>
            <xs:element name = 'student' type = 'StudentType' minOccurs = '0' 
               maxOccurs = 'unbounded' />
         </xs:sequence>
      </xs:complexType>
   </xs:element>
   <xs:complexType name = StudentType>
      <xs:sequence>
         <xs:element name = firstname type = xs:string/>
         <xs:element name = lastname type = xs:string/>
         <xs:element name = nickname type = xs:string/>
         <xs:element name = marks type = xs:positiveInteger/>
      </xs:sequence>
      <xs:attribute name = 'rollno' type = 'xs:positiveInteger'/>
   </xs:complexType>
</xs:schema>
<Schema>元素

Schema是XSD的根元素,它始终是必需的。

<xs:schema xmlns:xs = http://www.w3.org/2001/XMLSchema>
上面的片段指定模式中使用的元素和数据类型是在 http://www.w3.org/2001/XMLSchema 命名空间中定义的,这些元素/数据类型以xs为前缀。 它始终是必需的。

targetNamespace = http://www.jb51.cc
上面的片段指定此模式中使用的元素在 http://www.jb51.cc 命名空间中定义。 这是可选的。

xmlns = http://www.jb51.cc
上面的片段指定默认命名空间是 http://www.jb51.cc 。

elementFormDefault = qualified
上面的片段表明,在任何XML Document中使用它们之前,在此模式中声明的任何元素都必须是名称空间限定的。它是可选的。

引用架构
看看以下引用架构 -
<?xml version = 1.0?>
<class xmlns = http://www.jb51.cc
   xmlns:xsi = http://www.w3.org/2001/XMLSchema-instance
   xsi:schemaLocation = http://www.jb51.cc student.xsd>  
   <student rollno = 393>    
      <firstname>Dinkar</firstname>
      <lastname>Kad</lastname>
      <nickname>Dinkar</nickname>
      <marks>85</marks>
   </student>
   <student rollno = 493>     
      <firstname>Vaneet</firstname>
      <lastname>Gupta</lastname>
      <nickname>Vinni</nickname>
      <marks>95</marks>
   </student>
   <student rollno = 593>    
      <firstname>Jasvir</firstname>
      <lastname>Singh</lastname>
      <nickname>Jazz</nickname>
      <marks>90</marks>
   </student>
</class>
上面的片段指定默认名称空间声明。 模式验证器检查此命名空间是否所有元素都是此命名空间的一部分。它是可选的。

定义XMLSchema-instance xsi后,使用schemaLocation属性。 此属性有两个值,XML Schema的名称空间和位置,由空格分隔使用。它是可选的。

(编辑:大连站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章