XML简明教程(5)什么是XML名域

来源:互联网 发布:安卓软件源码是什么 编辑:程序博客网 时间:2024/05/01 08:24
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
XML名域是一组可以用作XML文档的元素或属性名称的名称集。为了避免元素之间出现相 同名称的冲突,名域限定Web中的名称必须是唯一的。名域由某些URI(Universal Reso urce Identifier)来进行识别,不管是URL(Uniform Resource Locator),还是URN( Uniform Resource Number)都没有关系,它并不管指向的什么内容。URI使用简单,因 为它们在Internet上是全球唯一的。

名域可以显式声明,也可以缺省声明。在显式声明中可以定义一个简写形式或是一个词 头来代替整个名域,可以使用这个词头来引用属于名域的元素。当节点包含不同名域的 元素时,显式声明非常有用。缺省声明声明一个可以被所有元素访问的名域,而且并不 定义词头。

<BOOKS>
<bk:BOOK XMLns:bk="urn:BookLovers.org:BookInfo"
XMLns:money="urn:Finance:Money"> 
<bk:TITLE>A Suitable Boy</bk:TITLE>
  <bk:PRICE money:currency="US Dollar">22.95</bk:PRICE>
 </bk:BOOK>
</BOOKS>

所有以"bk:"或"money:"开头的元素都可以看成是分别来自于名域"urn:BookLovers.org :BookInfo"或"urn:Finance:Money"。

如何声明缺省名域

名域声明时没有词头就属于文档的缺省名域,文档中所有没有词头的元素和属性都属 于缺省名域。下面的例子声明了<BOOK>元素和<BOOK>中所有的元素(<TITLE>, <PRICE> , currency)都属于名域"urn:BookLovers.org:BookInfo."。

<BOOK XMLns="urn:BookLovers.org:BookInfo">
  <TITLE>A Suitable Boy</TITLE>
  <PRICE currency="US Dollar">22.95</PRICE>
</BOOK>

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>