In XMLNamespaceAlso calledNamespace.
What is the role of a namespace?
To solveXMLConflict and differentiation of the same name of a word. (See the following example.)
Note:: The namespace only has a logical meaning and cannot be implementedUri.
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 includes the name prefix andUriAssociation.
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,ExplicitNamespace declaration:Xmlns:Prefix name="AUri"
For example:<Root elementXmlns: XG = http://xugang.cnblogs.com>
<XG:Child ElementAttname = "myname"/>
2,DefaultNamespace declaration:Xmlns ="AUri"
It has no prefix name, so inInclusionWithout a prefixXMLAll elements and attributes belong to the default namespace.
For example:<Root elementXmlns = "http://xugang.cnblogs.com">
<Child Element 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(Recommended)Explicit namespace Declaration).
Namespace DeclarationNote:
* 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 elementDeclareAllNamespace;
* 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.
UriYesURLAndUrn.
URL(Uniform Resource locater, Unified format Resource Locator): used to mark the location of a resource on the network, which is commonly referred to as the URL.
Urn(Uniform Resource Name, Unified format Resource Name): representsInternetOn a persistent (Persistent. For example:"Myurn: it"Indicates the internal name used in this example.
Example:
ItDepartment use. Xml
<? XML version = "1.0" encoding = "gb2312" standalone = "yes" ?>
< Materials >
< Device No. ="Lenovo 6515b " >
< Manufacturer > Lenovo Group </ Manufacturer >
< Address > No. 127, Zhongguancun, Beijing </ Address >
</ Device >
</ Materials >
Use by construction department. Xml
<? XML version = "1.0" encoding = "gb2312" standalone = "yes" ?>
< Materials >
< Device No. ="Zoomlion f001 " >
< Manufacturer > Zoomlion </ Manufacturer >
< Address > No. 113 xinkaipu, Changsha city, Hunan Province </ Address >
</ Device >
</ Materials >
IncorrectDepartment Integration. Xml
<? XML version = "1.0" encoding = "gb2312" standalone = "yes" ?>
< Materials >
< Device No. ="Lenovo 6515b "No. = "Zhonglian f001" >
< Device Name > Notebook </ Device Name >
< Manufacturer > Lenovo Group </ Manufacturer >
< Address > No. 127, Zhongguancun, Beijing </ Address >
< Device Name > Crane </ Device Name >
< Manufacturer > Zoomlion </ Manufacturer >
< Address > No. 113 xinkaipu, Changsha city, Hunan Province </ Address >
</ Device >
</ Materials >
CorrectDepartment Integration. Xml
<? XML version = "1.0" encoding = "gb2312" standalone = "yes" ?>
< Materials xmlns: it = "Http://www.lenovo.com" Xmlns: Architecture = "Myurn: Zhonglian" >
< Device it: No. = "Lenovo 6515b" Building: No. = "Zhonglian f001" >
< It: Device Name > Notebook </ IT: Device Name >
< It: Manufacturer > Lenovo Group </ IT: Manufacturer >
< It: Address > No. 127, Zhongguancun, Beijing </ IT: Address >
< Construction: Device Name > Crane </ Building: Device Name >
< Construction: Manufacturer > Zoomlion </ Construction: Manufacturer >
< Construction: Address > No. 113 xinkaipu, Changsha city, Hunan Province </ Building: Address >
</ Device >
</ Materials >
RelatedArticle:
Plan to use the XML namespace
Learn about XML Namespaces