看代码时经常碰到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).

什么是QName的更多相关文章

  1. Java 异常 —— java.io.InvalidClassException: javax.xml.namespace.QName; local class incompatible

    项目中有个 WebService 接口,调试时使用 Main 方法运行,别人的机器上都能运行,就笔者的机器出问题.他们说是RP的问题…… 异常信息: java.io.InvalidClassExcep ...

  2. Qname

    Qname的全称是qualified name. Qname由三部分组成: 1.Namespace prefix 2.A colon character(":") 3.A loca ...

  3. gsoap入门:C/C++代码生成及编译--包含soapcpp2 -qname添加命名空间后报错的解决方法--可用

    gsoap是什么 先来一段百度百科,说说gsoap是什么: gSOAP一种跨平台的开源的C/C++软件开发工具包.生成C/C++的RPC代码,XML数据绑定,对SOAP Web服务和其他应用形成高效的 ...

  4. 解决 weblogic poi3.9 报错 a different type with name "javax/xml/namespace/QName"

    解决 java.lang.LinkageError: loader constraint violation: loader (instance of weblogic/utils/classload ...

  5. Weblogic 9.2 启动时报错 javax.xml.namespace.QName

    启动Weblogic 时会报错.javax.xml.namespace.QName; local class incompatible: stream classdesc serialVersionU ...

  6. Access restriction: The type QName is not accessible due to restriction on required library

    There's another solution that also works. I found it on this forum: Go to the Build Path settings in ...

  7. 前端学HTTP之重定向和负载均衡

    前面的话 HTTP并不是独自运行在网上的.很多协议都会在HTTP报文的传输过程中对其数据进行管理.HTTP只关心旅程的端点(发送者和接收者),但在包含有镜像服务器.Web代理和缓存的网络世界中,HTT ...

  8. Android之SAX解析XML

    一.SAX解析方法介绍 SAX(Simple API for XML)是一个解析速度快并且占用内存少的XML解析器,非常适合用于Android等移动设备. SAX解析器是一种基于事件的解析器,事件驱动 ...

  9. java调用CXF WebService接口的两种方式

    通过http://localhost:7002/card/services/HelloWorld?wsdl访问到xml如下,说明接口写对了. 2.静态调用 // 创建WebService客户端代理工厂 ...

随机推荐

  1. Linux下 RabbitMQ的安装与配置-3

    一  Erlang安装 1.RabbitMQ是基于Erlang的,所以首先必须配置Erlang环境. 从Erlang的官网http://www.erlang.org/download.html 下载最 ...

  2. Ext.Net-Grid 篇

    概述 前两篇分别介绍了Ext.NET-基础 和 Ext.NET-布局,从本篇开始我们尽量做一些实际工作中用到的例子. 在Ext.NET官方示例中,关于GridPanel的例子是最多的(近百个),篇幅所 ...

  3. [HDOJ5439]Aggregated Counting(乱搞)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5439 题意:按规则构造一个数列a a(1)=1 a(2)=2 a(2)=2 -------> 写两个 ...

  4. SDN组网相关解决方案

    http://www.muzixing.com/pages/2016/02/14/sdnzu-wang-xiang-guan-jie-jue-fang-an.html 2016-02-14 by mu ...

  5. Javascript/jQuery 获取地址栏URL参数的方法

    1.jquery获取url很简单,代码如下 window.location.href; 2.javascript获取url参数 function getUrlParam(name) { var reg ...

  6. [转]java.sql.SQLException: 无效的列索引

    原文地址:http://blog.sina.com.cn/s/blog_6bc811e401011a17.html java.sql.SQLException: 无效的列索引 “无效的列索引”其实是个 ...

  7. NPOI使用手册[转]

    NPOI使用手册 目录 1.认识NPOI 2. 使用NPOI生成xls文件 2.1 创建基本内容 2.1.1创建Workbook和Sheet 2.1.2创建DocumentSummaryInforma ...

  8. HttpHelper类

    using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;usi ...

  9. Spring不支持依赖注入static静态变量

    在springframework里,我们不能@Autowired一个静态变量,使之成为一个spring bean,例如下面这样: 可以试一下,yourClass在这种状态下不能够被依赖注入,会抛出运行 ...

  10. bzoj1012

    Description 现在请求你维护一个数列,要求提供以下两种操作:1. 查询操作.语法:Q L 功能:查询当前数列中末尾L 个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度.2. ...