qname



Names were introduced by XML Namespaces in order to be used as URI references[1]. QName stands for "qualified name" and defines a valid identifier for elements and attributes. QNames are generally used to reference particular elements or attributes within XML documents. [2]

Contents

[hide]

[edit] Motivation

Since URI references can be long and may contain prohibited characters for element/attribute naming, QNames are used to create a mapping between the URI and a namespace prefix. The mapping enables the abbreviation of URIs, therefore it achieves a more convenient way to write XML documents. (see Example)

[edit] Formal definition

QNames are formally defined by the W3C as[3]:

  QName ::= PrefixedName | UnprefixedName
 
  PrefixedName   ::= Prefix ':' LocalPart
  UnprefixedName ::= LocalPart

Whereby the Prefix is used as placeholder for the namespace and the LocalPart as the local part of the qualified name. A local part can be an attribute name or an element name.

[edit] Example

  <?xml version='1.0'?>
  <doc xmlns:x="http://example.com/ns/foo">
    <x:p/>
  </doc>

In line two the prefix "x" is declared to be associated with the URI "http://example.com/ns/foo". This prefix can further on be used as abbreviation for this namespace. Subsequently the tag "x:p" is a valid QName because it uses the "x" as namespace reference and "p" as local part. The tag "doc" is also a valid QName, but it consists only of a local part.[4]


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值