XML constraints (Schema)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.