To resolve conflicts of the same name and distinguish between XML words in different fields. (See the example below) Note: The namespace only has a logical meaning and cannot really reference the URI. In XML
NamespaceAlso called
Namespace.
What is the role of a namespace?
To resolve conflicts of the same name and distinguish between XML words in different fields. (Refer to the example below)
Note:: The namespace only has a logical meaning and cannot really reference the URI.
Namespace declaration:
Put it in the starting label of the element (usually the root element) and declare it in the form of similar attributes.
The namespace declaration associates the name prefix with the URI.
Namespace scope:
OnlyDeclare namespace elementsAndElementAndAttribute.
(Note:Default namespaceDoes not apply directly to attributes)
The element that declares the namespace, calledInclusion(Container ). The association between the namespace and the prefix is valid within the range of the inclusion.
Two namespace claim methods:
1,Explicit namespace declaration:Xmlns: prefix = "a URI"
For example:
<根元素 xmlns: xg="“http://xugang.cnblogs.com”">
2,Default namespace declaration:Xmlns = "a URI"
It has no prefix name, so inInclusionThe XML elements and attributes without a prefix are all in the default namespace.
For example:
<根元素 xmlns="“http://xugang.cnblogs.com”">
<子元素 attName="“myname”" />
Note:TryRoot elementStatementDefaultNamespace. If the default namespace is declared inNon-root elementIs easy to be misunderstood or ignored by users as elements without namespaces. So,Non-root elementTryNot usedDefault namespace declaration (explicit namespace declaration is recommended ).
Note:
* The double quotation mark must be a URI;
* XML is case sensitive and the prefix name is no exception;
*Prefix nameWe recommend that you use English abbreviations or Chinese (but not Chinese );
* TryAvoid prefix with the same nameBut correspondsDifferent URIsIs easy to mislead users;
* TryRoot elementDeclare all namespaces;
* If the element of an attribute belongs to an explicitly declared namespace, you do not need to add a prefix for this attribute.
URI(Uniform Resource Identifier): Uniform format Resource Identifier.
URIYes URLAnd URN.
URL(Uniform Resource Locater): used to mark the location of a Resource on the network.
URN(Uniform Resource Name, Uniform format Resource Name): indicates a persistent Resource on the Internet. the format is relatively free. For example, "myURN: IT" indicates the internal name used in this example.
Example:
IT department uses. xml
<资料>
<设备 编号="联想6515b">
<生产商>
Lenovo Group
<地址>
No. 127, Zhongguancun, Beijing
The building department uses. xml
<资料>
<设备 编号="中联F001">
<生产商>
Zoomlion
<地址>
No. 113 xinkaipu, Changsha city, Hunan province
IncorrectDepartment fusion. xml
<资料>
<设备 编号="中联F001">
<设备名>
Notebook
<生产商>
Lenovo Group
<地址>
No. 127, Zhongguancun, Beijing
<设备名>
Crane
<生产商>
Zoomlion
<地址>
No. 113 xinkaipu, Changsha city, Hunan province
CorrectDepartment fusion. xml
<资料 xmlns:it="http://www.lenovo.com" xmlns:建筑="myURN:中联">
<设备 it:编号="联想6515b" 建筑:编号="中联F001">
Notebook
Lenovo Group
No. 127, Zhongguancun, Beijing
<建筑:设备名>
Crane
<建筑:生产商>
Zoomlion
<建筑:地址>
No. 113 xinkaipu, Changsha city, Hunan province
The above is the details about the example code of namespace in XML. For more information, see other related articles in the first PHP community!