什么是QName

什么是QName

标签: attributesnamespacesxmlreferencesoap文档
  13475人阅读  评论(2)  收藏  举报
  分类:

看代码时经常碰到QName,当时对这个东东具体什么意思也是不太明白;今天在看SOAP消息的时候,想到这个东东,就去仔细看了下。QName其实就是Qualified Name的简称,在“NameSpaces in XML1.0(Third Edition)”(http://www.w3.org/TR/REC-xml-names/#ns-qualnames)中有如下这段话:

URI references can contain characters not allowed in names, and are often inconveniently long, so expanded names are not used directly to name elements and attributes in XML documents. Instead qualified names are used. [Definition: A qualified name is a name subject to namespace interpretation. ] In documents conforming to this specification, element and attribute names appear as qualified names. Syntactically, they are either prefixed names or unprefixed names.

同时文中对QName的定义如下:

In XML documents conforming to this specification, some names (constructs corresponding to the nonterminal Name) MUST be given as qualified names,defined as follows:

Qualified Name

[7]   QName   ::=   PrefixedName
   UnprefixedName
[8]   PrefixedName   ::=   Prefix ':' LocalPart
[9]   UnprefixedName   ::=   LocalPart
[10]   Prefix   ::=   NCName
[11]   LocalPart   ::=   NCName

The Prefix provides the namespace prefix part of the qualified name, and MUST be associated with a namespace URI reference in a namespace declaration. [Definition: The LocalPart provides the local part of the qualified name.]

Note that the prefix functions only as a placeholder for a namespace name. Applications SHOULD use the namespace name, not the prefix, in constructing names whose scope extends beyond the containing document.

 

In XML documents conforming to this specification, element names are given as qualified names;

Attributes are either namespace declarations or their names are given as qualified names.

 

也就是说QName分为两种,一种是带前缀的名字,另一种是不带前缀的。若是带前缀,则前缀必须和命名空间的URI引用相关联,如

<namespace-prefix:envelope xmlns:namespace-prefix="namespaceURI"> ... </namespace-prefix:envelope>,其中<namespace-prefix:envelope>就是QName;不带前缀,也就是说xml文件使用的默认命名空间,如<rootElement xmlns="namespaceURI"> ... </rootElement>,这里<rootElement>就是QName;在xml文件中,元素和属性都是用QName表示的;

 

如果应用程序在构造QName的时候,同时这个QName的范围超过了其被包含的xml文档,比如应用程序是Java或C#程序,那么在构造QName的时候就需要使用命名空间,而不是前缀,QName可以看做是一个包含了命名空间和local part的二元组,如(namespace, local name).


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值