看代碼時(shí)經(jīng)常碰到QName,,當(dāng)時(shí)對(duì)這個(gè)東東具體什么意思也是不太明白,;今天在看SOAP消息的時(shí)候,想到這個(gè)東東,,就去仔細(xì)看了下,。QName其實(shí)就是Qualified Name的簡(jiǎn)稱,在“NameSpaces in XML1.0(Third Edition)”(http://www./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. 同時(shí)文中對(duì)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
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引用相關(guān)聯(lián),如 <namespace-prefix:envelope xmlns:namespace-prefix='namespaceURI'> ... </namespace-prefix:envelope>,其中<namespace-prefix:envelope>就是QName,;不帶前綴,,也就是說xml文件使用的默認(rèn)命名空間,如<rootElement xmlns='namespaceURI'> ... </rootElement>,,這里<rootElement>就是QName,;在xml文件中,元素和屬性都是用QName表示的,; 如果應(yīng)用程序在構(gòu)造QName的時(shí)候,,同時(shí)這個(gè)QName的范圍超過了其被包含的xml文檔,比如應(yīng)用程序是Java或C#程序,,那么在構(gòu)造QName的時(shí)候就需要使用命名空間,,而不是前綴,QName可以看做是一個(gè)包含了命名空間和local part的二元組,,如(namespace, local name). |
|