本文介绍了XML 中的命名空间和前缀有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被迫与外部 XML 作斗争,我不明白 XML 文件中的命名空间和前缀之间有什么区别.我的意思是,我正在使用命名空间和标签名称来通过 Linq 库获取此文件中的值.但我不知道它们之间的区别.

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?

推荐答案

XML 命名空间前缀是完整 XML 命名空间的缩写.

因为命名空间旨在区分不合格的 XML 名称,所以命名空间本身最好足够长,以便在添加到不合格名称之前创建一个词法上不同的新名称.与 URI 所有权一致的组织所有权是一个很好的属性,它也往往会增加命名空间长度.

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.

为了避免将完整的 XML 名称空间与不合格的 XML 名称笨拙地串联在一起,引入了一种缩写机制,

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"

允许将 RoutePointsMeteoData 作为 a:RoutePointsMeteoData 而不是 {http://example.com/some/full/命名空间/名称}RoutePointsMeteoData.(这种替代符号,称为 Clark Notation,不是标准化的——它不兼容直接使用 XML,但常用于元描述、JAXP API 规范中的参数名称等)

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)

进一步说明:

  • XML 命名空间前缀本身是任意的;只有通过他们绑定到他们派生的完整 XML 命名空间名称重要性.
  • XML 命名空间前缀必须声明,以便将 XML 文档视为 命名空间格式良好.

这篇关于XML 中的命名空间和前缀有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 20:50