What is the difference between namespace and prefix in XML?

痞子三分冷 提交于 2021-02-11 14:14:23

问题


I am forced to fight with an external XML and I do not understand what is the difference between namespace and prefix in a XML file. I mean, I am using namespace and name of the label to get a value in this file with Linq library. But I do not know the difference between these.

-<a:RoutePointsMeteoData z:Id="31" z:Size="10">
-<b:anyType z:Id="32" i:type="a:WaypointFLMeteoData">
    <a:DevISA>0</a:DevISA>
    <a:DisplayTemperatureType>IsaDev</a:DisplayTemperatureType>
    <a:RelatedRoutePointName>1739276a822f8a919b</a:RelatedRoutePointName>
    <a:TemperatureSource>NotDefined</a:TemperatureSource>
    <a:WindDirection>0</a:WindDirection>
    <a:WindSource>NotDefined</a:WindSource>
    <a:WindSpeed>0</a:WindSpeed>

Someone could tell me the main objective of use prefix in labels? For example:

<a:DevISA>0</a:DevISA>

What could be the purpouse of this a:? Is this a kind of distinctive feature to detect a label?


回答1:


An XML namespace prefix is an abbreviation for the full XML namespace.

Because namespaces are meant to differentiate unqualified XML names, it's better that the namespaces themselves be sufficiently long to create a lexically distinct new name when prepended to the unqualified names. Organizational ownership that's aligned with URI ownership is a nice property that also tends to increase namespace length.

To avoid unwieldy concatenation of a full XML namespace with an unqualified XML name, an abbreviation mechanism was introduced,

xmlns:a="http://example.com/some/full/namespace/name"

allowing RoutePointsMeteoData to be written in this namespace as a:RoutePointsMeteoData rather than, say, {http://example.com/some/full/namespace/name}RoutePointsMeteoData. (This alternative notation, known as Clark Notation, is not standardized – it's not compatible with XML directly, but is commonly used in meta descriptions, parameter names in JAXP API spec, etc)

Further notes:

  • XML namespace prefixes themselves are arbitrary; it's only through their binding to a full XML namespace name that they derive their significance.
  • XML namespace prefixes must be declared in order for an XML document to be considered to be namespace-well-formed.


来源:https://stackoverflow.com/questions/50912350/what-is-the-difference-between-namespace-and-prefix-in-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!