XML Schema is also a schema language used to define and describe the structure and content of XML documents, which appears to overcome the limitations of DTDsXML Schema conforms to XML syntax structureXML APIs such as DOM and sax can easily parse the contents of XML Schema DocumentsOne XML can have multiple schemas, multiple schemas are distinguished using namespaces (similar to Java-like package names)XML Schema supports more data types than XML DTD and enables users to customize new data typesthe ability to define constraints on XML Schemas is very powerful and allows for fine-grained semantic restrictions on XML instance documentsXML Schemas cannot define entities as DTDs, more complex than DTDs, but XML schemas are now the norm for the organization, and are gradually replacing DTDsSuffix named: *.xsd, must have a <schema> root nodePropertiesxmlns= "Http://www.w3.org/2001/XMLSchema"indicates that the current XML file is a constraint filetargetnamespace= "http://www.waykw.com/20160214"Use the schema constraint file to introduce constraint files directly from this addresselementformdefault= "qualified"Grammar(1) How many elements will be written <element name= "element name" ></element>(2) Whether the element is complex or simpleComplex elements:<complexType><sequence>child elements</sequence></complexType>simple elements are written in complex elements:
1 <ComplexType>2 <sequence>3 <elementname= "Name"type= "string"></element>4 <elementname= "Age"type= "int"></element>5 </sequence>6 </ComplexType>
All: Indicates only one occurrenceChoice: Only one of them can appearSequence: Elements appear in order
Maxoccurs= "unbounded": indicates there is no limit to the number of occurrences
1 < sequence > 2 < name= "name" type= "string"maxOccurs= "unbounded" ></element>3</sequence >
<any></any>: Represents any Elementdefining attributes (must be complex elements)written before </complexType><attribute name= "P1" type= "string"use= "Required" ></attribute>Name: Property nameType : Property value Typesuse: attribute constraints, optional optional, required must(3) Adding attributes to the root element in XMLxmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" at the end add-instanceindicates that XML is a constrained filexmlns= "Tartgetnamespace"targetnamespace in the schema constraint documentxsi:schemalocation= "tartgetnamespace schema file path"the location of the schema constraint document(4) Introduction of multiple schema files, you can give each constraint an aliasxmlns: alias = "schema file path"use < aliases when using constraints in another schema file: element name ></alias: element name >
XML constraints (Schema)