Sample XSD code for schema definition in XML Programming

Source: Internet
Author: User
This article mainly introduces the Schema Definition XSD in XML programming and explains how to declare the schema and definition type in XML documents, for more information about schema definition in XML programming, see the next article.

XML Schema is usually called XML Schema Definition (XSD ). It is used to describe and verify the structure and content of XML data. XML Schema defines elements, attributes, and data types. The schema element also supports namespaces. It is similar to the database mode that describes data in a database.

Syntax
We need to declare the schema in the XML document as follows:

 

Example

The following example shows how to use the mode:

   
   
        
             
                  
                   
                   
               
          
     
    
 

The basic idea behind the XML pattern is to describe the legal format acceptable to the XML document.

Element
As we can see in the XML element chapter, the element is the XML document building block. In XSD, elements can be defined as follows:

 

Define Type
We can define XML schema elements as follows:

Simple type: simple elements can only be used in text context. Some predefined simple types include: xs: integer, xs: boolean, xs: string, xs: data. For example:

 

Complex type: the complex type is the container defined by other elements. Allow us to specify which element can contain child elements to provide some structure for the XML document. For example:

       
            
                 
                  
                  
              
         
    
 

In the preceding example, the Address element consists of child elements. It is other The defined container allows us to build a simple hierarchical element in the XML document.

Global type: for the global type, we can define an independent type in the document, it can also use all other references. For example, suppose we want to summarize the person and company addresses for different companies. In this case, we can define a general type as follows:

       
            
                 
                  
              
         
    
 

Use this type in the following example:

       
            
                 
                  
              
         
    
   
       
            
                 
                  
              
         
    
 

You no longer need to define name and compacny twice (Address1 and Address2 at a time). now we have an independent definition. This makes maintenance easier. for example, if we decide to add a "Postcode" element to the address, we only need to add it in one place.

Attribute
Attributes in XSD provide additional information about elements. Attributes with the name and type attributes are as follows:

 

The above is a detailed description of the sample code for Schema Definition XSD in XML programming. For more information, see other related articles in the first PHP community!

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.