Acquaintance xsd

XML Schema language also called XML Schema definitions (XML Schema Definition, XSD)
element is the root element of each of the XML Schema.

Simple elements

<xs:element name="xxx" type="yyy"/>

常用type:
xs:string
xs:decimal
xs:integer
xs:boolean
xs:date
xs:time

Simple Default element and the fixed value

<xs:element name="color" type="xs:string" default="red"/>
<xs:element name="color" type="xs:string" fixed="red"/>

<xs:extension base="">Similar inherited
<xs:complexType>custom complex objects
restriction element defines constraints on simpleType, simpleContent or complexContent defined.
extension element to element simpleType or complexType to be extended.
sequence elements required elements in the group appear in the order specified in the containing element. Each child element can occur zero to any number of times.

abstract
an indicator indicating whether the complex type can be used in the instance document. If the value is true, then the element can not directly use the complex type, complex type must be derived from the complex type. The default value is false.
But I found the actual use can still use
cases:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="root" type="node"></xs:element>
    <xs:complexType name="complexType1"></xs:complexType>
    <xs:complexType name="complexType2"></xs:complexType>
    <xs:complexType name="complexType5" abstract="true"></xs:complexType>
    <xs:complexType name="complexType3">
        <xs:complexContent>
            <xs:extension base="complexType2">
                <xs:sequence>
                    <xs:element name="t1"></xs:element>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="complexType4">
        <xs:complexContent>
            <xs:extension base="complexType5">
                <xs:sequence>
                    <xs:element name="t1"></xs:element>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="node">
        <xs:sequence>
                <xs:element name="node1" type="complexType1"></xs:element>
                <xs:element name="node2" type="complexType2"></xs:element>
                <xs:element name="node3" type="complexType3"></xs:element>
                <xs:element name="node4" type="complexType5"></xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

But complexType4 obviously inherited complexType5, complexType5 is empty and the actual Altova XMLSpy generated message is so

<root xsi:noNamespaceSchemaLocation="Untitled6.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <node1/>
    <node2/>
    <node3>
        <t1>text</t1>
    </node3>
    <node4 xsi:type="complexType4">
        <t1>text</t1>
    </node4>
</root>

node4 not empty, there is great hope t1 node of what God can explain complexType4

Reference https://msdn.microsoft.com/zh-cn/library/ms256067(v=vs.120).aspx

Published 21 original articles · won praise 6 · views 30000 +

Guess you like

Origin blog.csdn.net/soulonlyhlh/article/details/78051575