javax.xml.namespace.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元素,其作用主要是增加了名字空间,比如有同样的元素名称,而名字空间不同的情况。


自己测试

// 指定名称空间 URI 和本地部分的 QName 构造方法。
//		QName qn=new javax.xml.namespace.QName("http://tempuri.org/", "resultXML");
		//指定名称空间 URI、本地部分和前缀的 QName 构造方法。
//		QName qn=new javax.xml.namespace.QName("http://tempuri.org/", "resultXML","/");
		//指定本地部分的 QName 构造方法。
		QName qn=new javax.xml.namespace.QName("resultXML");
		System.out.println("LocalPart:"+qn.getLocalPart());
		System.out.println("Prefix:"+qn.getPrefix());
		System.out.println("NameSapceUri:"+qn.getNamespaceURI());


仔细看下下面的东西:   我也是耐心了看了几遍才懂的。。。


4 Qualified Names

In XML documents conforming to this specification, some names (constructs corresponding to the nonterminalName)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 thenamespace prefix part of the qualified name, andMUST be associated with a namespace URI reference in a namespace declaration. [Definition: TheLocalPart provides thelocal part of the qualified name.]

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

5 Using Qualified Names

In XML documents conforming to this specification, element names are given asqualified names, as follows:

Element Names
[12]   STag   ::=   '<' QName (SAttribute)*S? '>'[NSC: Prefix Declared]
[13]   ETag   ::=   '</' QName S? '>'[NSC: Prefix Declared]
[14]   EmptyElemTag   ::=   '<' QName (SAttribute)*S? '/>'[NSC: Prefix Declared]

An example of a qualified name serving as an element name:

<!-- the 'price' element's namespace is http://ecommerce.example.org/schema -->
  <edi:price xmlns:edi='http://ecommerce.example.org/schema' units='Euro'>32.18</edi:price>

Attributes are either namespace declarations or their names are given asqualified names:

Attribute
[15]   Attribute   ::=   NSAttNameEqAttValue
   | QName Eq AttValue[NSC: Prefix Declared]
    [NSC: No Prefix Undeclaring]
    [NSC: Attributes Unique]

An example of a qualified name serving as an attribute name:

<x xmlns:edi='http://ecommerce.example.org/schema'>
  <!-- the 'taxClass' attribute's namespace is http://ecommerce.example.org/schema -->
  <lineItem edi:taxClass="exempt">Baby food</lineItem>
</x>



JDK   api文档里的跳转页面也有这些上面的资料    可以做去查下。。。。

转载于:https://my.oschina.net/u/141726/blog/407856

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值