Simplified XML tutorial (5)

Source: Internet
Author: User
Tags xml parser
An XML document can contain many elements and attributes. when we use an XML document of another person or use multiple validation files (DTD or Schema), the same element or attribute name may appear, these elements or attributes have different meanings. the class names of many classes in Java are the same, but the specific functions of these classes are different, as a result, the concept of package has been introduced in the Java field. classes with the same name under different packages have different functions, thus effectively distinguishing classes with the same name. Similarly, the introduction of namespaces in XML also aims to solve the problem of duplicate names. Let's take a look at the following example.

Directory

Development history

Comparison between XML and HTML

Syntax details for comparison between XML and HTML

DTD for XML verification

XML namespace

XML syntax structure

DOM4J read/write configuration file

About SLT

XML namespace


An XML document can contain many elements and attributes. when we use an XML document of another person or use multiple validation files (DTD or Schema), the same element or attribute name may appear, these elements or attributes have different meanings. the class names of many classes in java are the same, but the specific functions of these classes are different, as a result, the concept of package has been introduced in the Java field. classes with the same name under different packages have different functions, thus effectively distinguishing classes with the same name. Similarly, the introduction of namespaces in XML also aims to solve the problem of duplicate names. Let's take a look at the following example.

 
 
  
   In-depth JSP programming
   
    
Zhang San
   
   Writer
  
  
   From getting started to proficient in XML
   
    
Li Si
   
   Instructor
  
 



This is a well-formatted XML document about books, but the elements in the document conflict. The title element indicates the title and the title of the Author. the two elements with the same name have different meanings. This makes the XML parser difficult to read and cannot perform XML verification correctly. To solve this problem, we use namespaces to differentiate the same elements. Before that, we will first introduce how to define an XML namespace:

<元素名 xmlns:prefixname="URI">

An element name declares a namespace on this element. the namespace declared on this element applies to declaring its elements and attributes, the prefixname of all elements and attributes in the content of the element is the prefix of the namespace. the URI is usually long, so prefixname can be used to replace the URI. for example:

 


The above sentence declares a namespace whose name is #. Generally, this name is very long, so it is represented by hr. as an element or attribute in the namespace, you can add the prefix hr to it. For example It indicates that the employee element belongs to this namespace. Therefore, the above xml with duplicate title attributes can be written as follows to differentiate ambiguity.

 
 
  
   In-depth JSP programming
   
    
Zhang San
   
   Writer
  
  
   From getting started to proficient in XML
   
    
Li Si
    
     
Instructor
    
   
  
 



People is the prefix of namespace #, which indicates that the corresponding elements belong to the namespace. For the XML above, the parser can easily distinguish people: title from title.

There is another way to define a namespace:

<元素名 xmlns="URI">

This declaration does not provide a namespace prefix name. we can think that the URI identifies a default namespace. For example

Indicates a default namespace. Unless the element contains other namespaces to overwrite, all elements with no prefix in the hr element and its content belong to the namespace marked #.

After learning about the namespace, you can learn more easily and use Schema to verify the correctness of XML.

The above is the content of the simplified XML tutorial (5). For more information, see The PHP Chinese website (www.php1.cn )!

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.