您现在的位置:首页 >> 前端 >> 内容

scheam中的<anyAttribute>元素

时间:2013/10/28 14:08:16 点击:

  核心提示:[html]?xml version=1.0 encoding=UTF-8? xsi:schema xmlns:xsi=https://www.w3.org/2001/XMLSchema target...
[html] 

<?xml version="1.0" encoding="UTF-8"?>  

<xsi:schema xmlns:xsi="https://www.w3.org/2001/XMLSchema" targetNamespace="https://www.w3.org/"  

    xmlns:tns="https://www.w3.org/" elementFormDefault="qualified">  

    <xsi:element name="persons">  

      

    </xsi:element>  

</xsi:schema>  

 

[html]  

<?xml version="1.0" encoding="UTF-8"?>  

<xs:schema xmlns:xs="https://www.w3.org/2001/XMLSchema"  

    targetNamespace="https://www.example.org/family" xmlns:tns="https://www.example.org/family"  

    elementFormDefault="qualified">  

    <xs:element name="person">  

        <xs:complexType>  

            <xs:sequence>  

                <xs:element name="firstname" type="xs:string"></xs:element>  

                <xs:element name="lastname" type="xs:string"></xs:element>  

            </xs:sequence>  

            <xs:anyAttribute/><!-- <anyAttribute> 元素使我们有能力通过未被 schema 规定的属性来扩展XML文档! -->  

        </xs:complexType>  

    </xs:element>  

</xs:schema>  

 

[html]  

<?xml version="1.0" encoding="UTF-8"?>  

<xs:schema xmlns:xs="https://www.w3.org/2001/XMLSchema"  

    targetNamespace="https://www.example.org/children" xmlns:tns="https://www.example.org/children"  

    elementFormDefault="qualified">  

    <xs:attribute name="sex"><!-- 创建属性名称为sex的属性 -->  

        <xs:simpleType>  

            <xs:restriction base="xs:string"><!-- 创建的约束条件 -->  

                <xs:enumeration value="男"></xs:enumeration><!-- 规定属性值得范围 -->  

                <xs:enumeration value="女"></xs:enumeration>  

            </xs:restriction>  

        </xs:simpleType>  

    </xs:attribute>  

</xs:schema>  

 

[html]  

<?xml version="1.0" encoding="UTF-8"?>  

<persons xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"  

    xmlns="https://www.w3.org" xmlns:fm="https://www.example.org/family"  

    xmlns:ch="https://www.example.org/children"  

    xsi:schemaLocation="https://www.w3.org per.xsd https://www.example.org/family family.xsd https://www.example.org/children children.xsd">  

    <fm:person ch:sex="男">  

        <fm:firstname></fm:firstname>  

        <fm:lastname></fm:lastname>  

    </fm:person>  

    <fm:person ch:sex="女">  

        <fm:firstname></fm:firstname>  

        <fm:lastname></fm:lastname>  

    </fm:person>  

</persons>  

 

Tags:SC CH HE EA 
作者:网络 来源:不详