Detailed introduction to XMLDTD's sample code for XMLSchema learning

Source: Internet
Author: User
XML (eXtensibleMarkupLanguage) extensible markup language. Xml is particularly important in webservice programming. It can be used as a carrier for data transmission during network transmission. Xml, as a metadata language, can be used to mark and define data types. it is a metadata language that allows users to define their own markup languages. It is ideal for network transmission and provides a unified way to describe and exchange structured data independent of applications or vendors. Allows interaction between heterogeneous languages and platforms. XML document definition methods include Document Type Definition (DTD) and XMLSchema. The eXtensible Markup Language of DTD (DocumentTypeDef XML (eXtensible Markup Language. Xml is particularly important in web service programming. In network transmission Data transmission carrier. Xml MetaBaseIt can be used to mark data and define data types. it is a metalanguage that allows users to define their own markup language. It is ideal for network transmission and provides a unified way to describe and exchange structured data independent of applications or vendors. Allows interaction between heterogeneous languages and platforms. XML document definition methods include Document Type Definition (DTD) and XML Schema. Document Type Definition (DTD) defines the overall structure of the Document and the syntax of the Document (the following example is used for understanding). It is widely used and supports a wide range of tools. XML Schema is more powerful and used to define management information and other more powerful and richer features. XML can declare content in a more fine-grained manner and define constraints to facilitate more meaningful transfer of content across multiple platforms. It provides a format for describing structured data, simplifies data exchange and representation in the network, separates code, data, and representation, and serves as a standard format for data exchange, therefore, it is often called smart data documentation. The DTD can be compared to the shovel, and the XML Schema can be called an excavator with more powerful functions. Although XML is called a markup language, unlike HTML (Hypertext Markup Language), XML adopts a more strict format, tags must be closed, and display and content are separated, XML describes the content and semantics of a document, rather than how the document is displayed. HTML has fixed tags, and the display and content are the same. you cannot create your own tags. XML is scalable, and the content and display are separated. each element becomes a pair, it ends at the beginning, and the nesting relationship of XML elements must be correct (the starting mark in nesting must end first, and the starting mark must end later ), each XML document contains only one Root Element. the Root Element contains all other elements. XML documents that conform to the XML syntax are called well form when they are not verified by DTD or XML Schema. if the xml documents that conform to the XML syntax are verified by DTD or XML Schema, this xml document is called a Valid (Valid.

The following uses the xml of a student register as an example.

 
 <学生名册>    
  <学生 学号="A1">        
   <姓名>
    
CIACs
           
   <性别>
    
Male
           
   <年龄>
    
22
       
      
  <学生 学号="A2">        
   <姓名>
    
Zhihao
           
   <性别>
    
Male
           
   <年龄>
    
23
       
  
 

The output window of XMLSpy will output the following results.

The first line of xml must be Process the command, and" Xml elements are case sensitive.The default document encoding format is"UTF-8", The version is only 1.0. The preceding xml document can only be a well-formatted xml document, not a valid (Vaild) xml document. We can verify it in two ways.

First, it is verified through DTD.

 
 
 
 
 
 
 ]>
 <学生名册>    
  <学生 学号="A1">        
   <名字>
    
CIACs
           
   <性别>
    
& Sex;
           
   <年龄>
    
22
       
          
  <学生 学号="A2">        
   <名字>
    
Zhihao
           
   <性别>
    
& Sex;
           
   <年龄>
    
23
       
  
 

If the verification is successful, the XMLSpy output window displays the following results:

Otherwise, verification fails even if a space is added. Here I write the dtd verification to xml. of course you can also write it to another file with the suffix ". and associate it with the xml document to be verified. The syntax is as follows:

1

The ID value must start with a character. if it is only a number, it cannot be verified.

The gender in the student information. I define it as an entity and reference its value through the entity. Note that the syntax of object reference is"& Entity name;".

The following is an XML Schema verification method.

Xml document to be verified

 
 <学生名册 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nonamespaceschemalocation="学生名册.xsd">    
  <学生 学号="A1">        
   <姓名>
    
CIACs
           
   <性别>
    
Male
           
   <年龄>
    
22
       
      
  <学生 学号="A2">        
   <姓名>
    
Zhihao
           
   <性别>
    
Male
           
   <年龄>
    
23
       
  
 

XML Schema verification document

 
     
          
               
                    
                 
            
       
      
          
               
                    
                     
                         
       
        
         
         
        
                      
                     
                         
       
        
         
         
        
                      
                 
                
            
       
  
 

Output result of XMLSpy output window

From the above two verification methods, we can clearly see the difference between DTD and XML Schema verification. The two are also for xml document verification. XML Schema provides more powerful functions than DTD andMore fine-grained data typesAnd the Schema can also customize the data type, which is an xml file, but the dtd syntax is different from the xml syntax. Although the Schema is larger than the dtd in terms of code, you will prefer Schema after learning the Schema.

Learning xml and its verification methods are important for later learning web service programming.

The above is a detailed description of the sample code (text) for learning xml dtd in XML Schema. 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.