Home > Backend Development > XML/RSS Tutorial > XML introductory tutorial-detailed introduction to XML namespaces

XML introductory tutorial-detailed introduction to XML namespaces

黄舟
Release: 2017-03-15 16:54:37
Original
1540 people have browsed it

XMLThe namespace indicates the usage range of XML names. Because XML can customize element tags, there is a high chance that XML names will overlap between different XML applications.

Without a way to differentiate between names that don't apply, confusion would result. XML namespaces are designed to solve this problem. Through the XML namespace, we can distinguish the XML names from different XML applications. very big. Without a way to differentiate between names that don't apply, confusion would result. XML namespaces are designed to solve this problem. Through XML namespaces, we can distinguish elements and attributes with the same name from different XML applications. Related elements and attributes from a single XML application can be grouped together to facilitate software identification and processing.
Namespaces are grouped by prefix and local , separated by colons. The prefix identifies the namespace in which the element or attribute resides, and the local part identifies an element or attribute within the namespace. The entire name is also called a qualified name (qual
ified name). The prefix can be composed of any legal XML name characters except the three letters of XML (in any combination of upper and lower case). Each prefix in a qualified name must be associated with a unique URI. Names associated with the same URI prefix belong to the same namespace.

The prefix is ​​generally defined in the top-level element using the prefix. Different prefixes can also be defined in lower-level elements:

<rdf:RDF xmlns:rdf="http://www.w3.org/TR/REC-rdf-syntax#"> 
<rdf:Description xmlns:dc="http://www.w3.org/dc/" about="http://www.example.com/test.xml"> 
<dc:title>example</dc:title> 
<dc:author>linuxsir</dc:author> ... </rdf:Description> 
</rdf:RDF>
Copy after login

By appending the unprefixed xmlns attribute to the root element, you can specify that the element without the prefix and all the child elements without the prefix belong to a certain namespace.

<svg xmlns="http://www.w3.org/2000/svg"> 
<ellipse rx="110" ry="130" /> 
<rect x="4cm" y="1cm" /> 
</svg>
Copy after login

If the namespace is only used to identify elements and attributes from a certain XML application, and is not used to distinguish different elements with the same name, it can be used in
DTD

A fixed xmlns attribute is defined in the element and does not need to be defined in the document. The definition method is as follows:


When defining a DTD, if you need to use a namespace prefix, you must also write the prefix into the DTD definition when defining, such as:

<!ELEMENT xlink:name (#PCDATA)>
Copy after login


Using parameter entities

Reference

to define the namespace prefix can facilitate the maintenance, organization and release of DTD documents! Please indicate the source when reprinting, thank you!


Then, use the parameter entity name to define more parameter entity references, such as:

<!ENTITY % xlink-title "%prefix;%colon;title"> <!ENTITY % xlink-author "%prefix;%colon;author">
Copy after login


In this way, if you need to change the prefix, You only need to modify one place, not the entire document.

<!ELEMENT %xlink-title; (#PCDATA)> 
<!ELEMENT %xlink-author; (#PCDATA)> 
不能在ATTLIST和ELEMENT声明中直接使用%prefix;和%colon;,
因为在另一个实体的外部使用这些参数实体时,XML解析器会在实体替换文本的两边添加额外的空格。
Copy after login

The above is the detailed content of XML introductory tutorial-detailed introduction to XML namespaces. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template