zoukankan      html  css  js  c++  java
  • xml的schema约束

    约束文件

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- 
        
        模拟servlet2.5规范,如果开发人员需要在xml使用当前Schema约束,必须包括指定命名空间。
        格式如下:
        <web-app xmlns="http://www.example.org/web-app_2_5" 
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://www.example.org/web-app_2_5 web-app_2_5.xsd"
                version="2.5">
    -->
    <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" 
        targetNamespace="http://www.example.org/web-app_2_5"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:tns="http://www.example.org/web-app_2_5" 
        elementFormDefault="qualified">
        
        <xsd:element name="web-app">
            <xsd:complexType>
                <xsd:choice minOccurs="0" maxOccurs="unbounded">
                    <xsd:element name="servlet">
                        <xsd:complexType>
                            <xsd:sequence>
                                <xsd:element name="servlet-name"></xsd:element>
                                <xsd:element name="servlet-class"></xsd:element>
                            </xsd:sequence>
                        </xsd:complexType>
                    </xsd:element>
                    <xsd:element name="servlet-mapping">
                        <xsd:complexType>
                            <xsd:sequence>
                                <xsd:element name="servlet-name"></xsd:element>
                                <xsd:element name="url-pattern" maxOccurs="unbounded"></xsd:element>
                            </xsd:sequence>
                        </xsd:complexType>
                    </xsd:element>
                    <xsd:element name="welcome-file-list">
                        <xsd:complexType>
                            <xsd:sequence>
                                <xsd:element name="welcome-file" maxOccurs="unbounded"></xsd:element>
                            </xsd:sequence>
                        </xsd:complexType>
                    </xsd:element>
                </xsd:choice>
                <xsd:attribute name="version" type="double" use="optional"></xsd:attribute>
            </xsd:complexType>
        </xsd:element>
    </xsd:schema>

    根据约束文件 写的xml文件

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://www.example.org/web-app_2_5" 
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="http://www.example.org/web-app_2_5 web-app_2_5.xsd"
                version="2.5">
        <servlet>
            <servlet-name></servlet-name>
            <servlet-class></servlet-class>
        </servlet>        
                
        <servlet-mapping>
            <servlet-name></servlet-name>
            <url-pattern></url-pattern>
        </servlet-mapping>        
                
    </web-app>            
     xmlns="http://www.example.org/web-app_2_5 自定义命名空间
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 实例文档
     xsi:schemaLocation="http://www.example.org/web-app_2_5 web-app_2_5.xsd" 本地的命名空间

    这三个是必须要声明的
  • 相关阅读:
    Caliburn Micro 框架 WP8使用研究(二)页面导航
    Windows Phone 8 Fast Resume 快速恢复浅析(二)
    Caliburn Micro 框架 WP8使用研究(一)简介
    当BI迈入云端,分析云为我们带来了什么?
    解读SQL Server 2012中的最新BI功能
    一个典型的BI系统介绍
    SQL Server数据库服务器的负载均衡集群实现方法
    Web数据挖掘在电子商务中的应用
    2012商业智能发展趋势预测
    一个商业智能培训经理眼中的商业智能
  • 原文地址:https://www.cnblogs.com/benjamin77/p/9171778.html
Copyright © 2011-2022 走看看