解释XSL的QName

转:http://hi.baidu.com/haojian/blog/item/66ef480834cbe1920b7b82a0.html

 

Qname这个东东,在使用dom4j的时候,经常见到,可能是自己解析的xml都太简单了,所以没有仔细研究过,就是觉得名字很怪异,在google百度搜索“什么是qname”,居然只有几条没有像样答案的纪录。还好,在国外网站上找到了相关的解释,这下基本明白了。
1.来历:qname是qualified name 的简写
2.构成:由名字空间(namespace)前缀(prefix)以及冒号(:),还有一个元素名称构成
3.举例:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
      version="1.0">
   <xsl:template match="foo">
     <hr/>
   </xsl:template>
</xsl:stylesheet>
xsl是名字空间前缀,template是元素名称,xsl:template 就是一个qname
4.总结:qname无非是有着特定格式的xml元素,其作用主要是增加了名字空间,比如有同样的元素名称,而名字空间不同的情况。先了解这么多,请大家补充。
参考地址:

http://infohost.nmt.edu/tcc/help/pubs/pyxml/def-qname.html
原文如下:

A document may contain elements and attributes from more than one namespace URI. Because namespace URIs can be quite lengthy, it is cumbersome to include the complete namespace URI in each element or attribute name.

XML allows a shorthand notation to simplify assigning names to namespaces. You may invent a short namespace prefix and associate it with a namespace URI.

For example, suppose your document contains names from both the XSLT and XHTML namespaces. In this situation, it is customary to associate the namespace prefix “xsl” with XSLT. You might use prefix “html” to refer to the XHTML namespace.

A qualified name has three parts:

A namespace prefix.

A colon character, “:”.

A local name that gives the name of the element or attribute within that namespace.

For example, here is a fragment illustrating the use of qualified names:

<xsl:template match="separator">   <html:hr/></xsl:template>

Element template is in the XSLT namespace, and element hr is in the HTML namespace.

You can also use an unqualified name, which is just a local name without the namespace prefix. The namespace of such a name is called the default namespace.

The association between a namespace prefix and a namespace URI is made with an xmlns attribute located in some element. This attribute can have two forms:

An attribute named xmlns='nsURI' defines the namespace URI of the default namespace. This namespace is associated with all elements and attributes that have unqualified names.

An attribute named xmlns:prefix='nsURI' associates the given prefix with the namespace URI nsURI.

Here is an example of a complete document using elements from two namespaces:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"      xmlns="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"      version="1.0">   <xsl:template match="foo">     <hr/>   </xsl:template></xsl:stylesheet>
In this example, the template element is in the XSLT namespace. The hr element is in the default namespace, which is associated with the XHTML namespace URI.

xalan   中有一个类叫QName,用于参数、属性等等地方,比如象这个样子:  
{http://a.b.c/d/e.html}fghi  
   
public   class   QName  
extends   java.lang.Object  
implements   java.io.Serializable  
   
Class   to   represent   a   qualified   name:   "The   name   of   an   internal   XSLT   object,   specifically   a   named   template   (see   [7   Named   Templates]),   a   mode   (see   [6.7   Modes]),   an   attribute   set   (see   [8.1.4   Named   Attribute   Sets]),   a   key   (see   [14.2   Keys]),   a   locale   (see   [14.3   Number   Formatting]),   a   variable   or   a   parameter   (see   [12   Variables   and   Parameters])   is   specified   as   a   QName.   If   it   has   a   prefix,   then   the   prefix   is   expanded   into   a   URI   reference   using   the   namespace   declarations   in   effect   on   the   attribute   in   which   the   name   occurs.   The   expanded   name   consisting   of   the   local   part   of   the   name   and   the   possibly   null   URI   reference   is   used   as   the   name   of   the   object.   The   default   namespace   is   not   used   for   unprefixed   names."     

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值