The 3rd chapter of the learning process of the "XML Getting Started classic" namespace

Source: Internet
Author: User
Tags intl xml parser

After the XML parser parses the XML document and passes the data to the application, the application needs to combine elements from different documents into the same XML document.

Whether you are in the same document or in a different document, you can add a prefix to each element in order to resolve the problem of naming conflicts. However, this approach also has the disadvantage that the browser may not be able to read the XHTML content in the XML document properly before adding a prefix to the HTML XML version of the element.

Namespaces are just "container-loading" functions, and there is no point in anything else.

Namespaces are defined, but who manages these namespaces? The namespace prefix itself must be unique for the namespace to be valid. The solution to this problem is similar to the domain name management method on the Internet, which is to apply a prefix to the prefix manager before using it, and if the prefix has not been used by another person or company, then the prefix can be used.

The operating mechanism of the namespace:

When we want to use namespaces in an XML document, the concept of the element name becomes the so-called qualified name. It consists of two parts: The local part, the element name we have previously called, and the namespace prefix, which determines the namespace in which the name resides.

Pay particular attention to the syntax of the declaration XML namespace that is described in the book.

For example, start tag <pers:person xmlns:pers= "Http://www.wiley.com/pers", which indicates that the person element belongs to the namespace referred to by Pers.

With a namespace, an element cannot be identified by its name only, but by its qualified name.

When an XML document is parsed, the parser replaces all of the namespace prefixes with the namespace, which is the content in xmlns.

The default namespace:

The standard syntax requires that we add a namespace prefix to each element name, but the form of the document is less beautiful. To solve this problem, we can use the default namespace. That is, in the above start tag omit the writing and declaration of the prefix, so that it can be written as <person xmlns= "Http://www.wiley.com/pers", this start tag corresponding to the end of the tag and the label of all the element name will not have to add a prefix, Their namespaces belong to "Http://www.wiley.com/pers" by default. Of course, only one default namespace can be used in the same tag , and if you want to use a namespace again, you have to declare a namespace prefix.

Note the more usage of the namespaces that are described in the book.

Namespaces and properties:

Namespaces have a different effect on an element than it does on properties. Although an element is part of a namespace, its properties are only associated with the element to which it belongs, and if you want to make a property subordinate to a namespace, the property must have a namespace prefix before it.

URI:

A URI (Uniform Resource Identifier) is a string used to identify a resource. It has two forms: URL and urn.

The first part of the URL uses protocol (scheme), usually the HTTP protocol. The protocol is followed by a colon, and the colon is followed by the path to the resource.

For example, http://www.google.com/intl/en/about.html is the URL of a Web page. This URL indicates that a file named About.html is retrieved from a server named www.google.ca on the Internet, which is located in the/intl/en directory and must be read by the HTTP protocol.

Resources that can be retrieved through URLs are limited because they can only be read from the computer.

urns are not used very often. Their presence provides a persistent, location-independent name for the resource.

The reason why the XML namespace is represented by a URL instead of a urn:

The URL itself retains its uniqueness, so it is easier to create a namespace with a domain name.

The true meaning of the namespace URI:

According to the XML namespace specification, a URI is simply used to give a namespace a name, except that it doesn't make any sense. The XML parser does not attempt to enter the URL and does not retrieve anything. Of course, for specific applications, they can take advantage of these URLs to their own needs.

The 3rd chapter of the learning process of the "XML Getting Started classic" namespace

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.