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. <rdf:RDF xmlns:rdf="http://www.w3.org/TR/REC-rdf-syntax#">
<rdf:Description about="http://www.example.com/test.xml">
<title>example</title>
<author>linuxsir</author> ... </rdf:Description>
</rdf:RDF>
<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>
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>
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
<!ATTLIST svg xmlns CDATA #FIXED "http://www.w3.org/svg/">
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)>
to define the namespace prefix can facilitate the maintenance, organization and release of DTD documents! Please indicate the source when reprinting, thank you! <!ENTITY % prefix "xlink"> <!ENTITY % colon ":">
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">
<!ELEMENT %xlink-title; (#PCDATA)> <!ELEMENT %xlink-author; (#PCDATA)> 不能在ATTLIST和ELEMENT声明中直接使用%prefix;和%colon;, 因为在另一个实体的外部使用这些参数实体时,XML解析器会在实体替换文本的两边添加额外的空格。
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!