LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1943|回复: 0

RDF之旅

[复制链接]
发表于 2007-1-14 09:29:17 | 显示全部楼层 |阅读模式
XML目前用处最多的地方是web service,而RSS是其中的一种服务,同时主流浏览器提供的XMLHttpRequest JS类也提供了异步获取XML信息的能力。另外熟悉XUL模版的人知道,通过给定一个RDF的URI,XUL控件可以绑定一个数据源。(.net有没有这样的功能??)再加上IE和FF对RDF格式文件的友好支持,所以作为RSS及其它一些web service的基础,RDF开始流行起来。

RDF的全称是Resouce Decription Framework(资源描述框架),是W3C组织推荐的国际标准。可以用它来描述存在于互联网上的任意资源,以使这些信息可以在不同的平台和操作系统上共享。

RDF通过URI来认定资源,并用属性以及属性值来描述资源。而资源,属性,属性值三者的组合则构成一个声明,举个例子来说。
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <rdf:RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  3. <rdf:Description rdf:about="http://www.fict-tutorial.com/RDF">
  4. <author>鲁迅</author>
  5. <homepage>http://www.fict-tutorial.com</homepage>
  6. </rdf:Description>
  7. </rdf:RDF>
复制代码
在这个例子中,有两个声明存在。一个是资源http://www.fict-tutorial.com/RDF的作者是鲁迅。另一个是资源 http://www.fict-tutorial.com/RDF的首页在http://www.fict-tutorial.com[/url]。因为RDF创造出来是给机器交换数据用的,所以比较的抽象。

属性元素也可以被定义为特征,可以将上面的例子改为 :
  1. <rdf:RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  2. <rdf:Description rdf:about="http://www.fict-tutorial.com/RDF" author="鲁迅"  homepage="http://www.fict-tutorial.com"/>
  3. </rdf:RDF>
复制代码
属性元素也可以不具有值,而是指向一个资源。可以将最前面的例子改为:
  1. <rdf:Description rdf:about="http://www.fict-tutorial.com/RDF">
  2. <author rdf:resouce="http://www.referenced.com/author" />
  3. <homepage>http://www.fict-tutorial.com《/homepage>
  4. </rdf:Description>
  5. </rdf:RDF>
复制代码
下面再介绍一下rdf容器,它是用来将一系列资源进行分组用的。这些元素有三类,<Bag>,<Seq>,<Alt>,如下面的例子:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <rdf:RDF
  3. xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  4. xmlns:cd="http://www.bookday.fake/cd#">
  5. <rdf:Description
  6. rdf:about="http://www.recshop.fake/cd/Beatles">
  7. <cd:artist>
  8. <rdf:Bag>
  9. <rdf:li>John</rdf:li>
  10. <rdf:li>Paul</rdf:li>
  11. <rdf:li>George</rdf:li>
  12. <rdf:li>Ringo</rdf:li>
  13. </rdf:Bag>
  14. </cd:artist>
  15. </rdf:Description>
  16. </rdf:RDF>
复制代码
Seq和Alt都是跟Bag相同的语法,他们的区别是Bag中存放的成员是未经排序的,Seq中是排序了的,Alt中是待选择,用户可以任选其中之一。

还有一种特殊的集合,它指定某个某个属性仅仅是由一系列成员构成,这就是rdf:parseType=”Collection”。它里面的存放的是资源描述符,指定着特指的有些成员。

这些就是基本的RDF概念了。下面还会介绍一些RDF的扩展。

如果要定义应用相关的一些类和属性,就会用到RDF schema。这些元素定义在xmlns:rdfs=”http://www.w3.org/2000/01/rdf-schema#”里。如下面的例子:
  1. <rdf:RDF
  2. xmlns:rdf= "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  3. xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
  4. xml:base=  "http://www.animals.fake/animals#">
  5. <rdfs:Class rdf:ID="animal" />
  6. <rdfs:Class rdf:ID="horse">
  7. <rdfs:subClassOf rdf:resource="#animal"/>
  8. </rdfs:Class>
  9. </rdf:RDF>
复制代码
在上面的例子中,利用shema中的Class元素定义了animal类,用subClassOf元素指定了horse属于animal类。

至此,RDF之旅行将结束。

最后算附录:rdf的Mimetype 是application/rdf+xml

rdf及rdfs的元素有以下表可以查询。
RDFS / RDF Classes
Element         Class of         Subclass of
rdfs:Class         All classes        
               
rdfsatatype         Data types         Class
rdfs:Resource         All resources         Class
               
rdfs:Container         Containers         Resource
rdfsiteral         Literal values (text and numbers)         Resource
               
rdfist         Lists         Resource
rdfroperty         Properties         Resource
rdf:Statement         Statements         Resource
               
rdf:Alt         Containers of alternatives         Container
rdf:Bag         Unordered containers         Container
rdf:Seq         Ordered containers         Container
               
rdfs:ContainerMembershipProperty         Container membership properties         Property
rdf:XMLLiteral         XML literal values         Literal

RDFS / RDF Properties
Element         Domain         Range         Description
rdfs:domain         Property         Class         The domain of the resource
rdfs:range         Property         Class         The range of the resource
rdfs:subPropertyOf         Property         Property         The property is a sub property of a property
                       
rdfs:subClassOf         Class         Class         The resource is a subclass of a class
rdfs:comment         Resource         Literal         The human readable description of the resource
rdfs:label         Resource         Literal         The human readable label (name)  of the resource
rdfs:isDefinedBy         Resource         Resource         The definition of the resource
rdfs:seeAlso         Resource         Resource         The additional information about the resource
rdfs:member         Resource         Resource         The member of the resource
                       
rdf:first         List         Resource        
rdf:rest         List         List        
rdf:subject         Statement         Resource         The subject of the resource in an RDF Statement
rdf:predicate         Statement         Resource         The predicate of the resource in an RDF Statement
rdfbject         Statement         Resource         The object of the resource in an RDF Statement
rdf:value         Resource         Resource         The property used for values
rdf:type         Resource         Class         The resource is an instance of a class

RDF Attributes
Element         Domain         Range         Description
                       
rdf:about                         Defines the resource being described
rdfescription                         Container for the description of a resource
rdf:resource                         Defines a resource to identify a property
rdf:datatype                         Defines the data type of an element
rdf:ID                         Defines the ID of an element
rdf:li                         Defines a list
rdf:_n                         Defines a node
rdf:nodeID                         Defines the ID of an element node
rdf:parseType                         Defines how an element should be parsed
rdf:RDF                         The root of an RDF document
xml:base                         Defines the XML base
xml:lang                         Defines the language of the element content
                       
rdf:aboutEach                         (removed)
rdf:aboutEachPrefix                         (removed)
rdf:bagID                         (removed)

Posted in GNU/Linux | Edit| No Comments »
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表