1

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?

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
JoseJimRin
  • 372
  • 1
  • 4
  • 20
  • Possible duplicate of [What does "xmlns" in XML mean?](https://stackoverflow.com/questions/1181888/what-does-xmlns-in-xml-mean) – Joe Jun 19 '18 at 12:04
  • Do you read the question Joe? – JoseJimRin Jun 19 '18 at 12:18
  • I did. You're asking for an explanation of XML namespaces and prefixes, and the linked question has a good answer. – Joe Jun 19 '18 at 12:40

1 Answers1

3

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.
kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • 1
    The other important point is that *different people can use different prefixes (abbreviations) for the same namespace*. Your `p:foo` can be the same thing as my `q:foo` if your `p` is bound to the same namespace as my `q`. – Michael Kay Jun 18 '18 at 22:09
  • @MichaelKay: Right, that follows from the mentioned note about the arbitrariness of the namespace prefixes, but the implication is worth highlighting. Thank you. – kjhughes Jun 18 '18 at 23:10