Latest web development tutorials

RDF 主要元素

RDF的主要元素是<RDF>以及可表示某個資源的<Description>元素。


<rdf:RDF> 元素

<rdf:RDF> 是RDF 文檔的根元素。 它把XML 文檔定義為一個RDF 文檔。 它也包含了對RDF 命名空間的引用:

<?xml version="1.0"?>

<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
...Description goes here...
</rdf:RDF>


<rdf:Description> 元素

<rdf:Description> 元素可通過about 屬性標識一個資源。

<rdf:Description> 元素可包含描述資源的那些元素:

<?xml version="1.0"?>

<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cd="http://www.recshop.fake/cd#">

<rdf:Description
rdf:about="http://www.recshop.fake/cd/Empire Burlesque">
<cd:artist>Bob Dylan</cd:artist>
<cd:country>USA</cd:country>
<cd:company>Columbia</cd:company>
<cd:price>10.90</cd:price>
<cd:year>1985</cd:year>
</rdf:Description>

</rdf:RDF>

artist、country、company、price 以及year 這些元素被定義在命名空間http://www.recshop.fake/cd# 中。 此命名空間在RDF 之外(並非RDF 的組成部分)。 RDF 僅僅定義了這個框架。 而artist、country、company、price 以及year 這些元素必須被其他人(公司、組織或個人等)進行定義。


屬性(property)來定義屬性(attribute)

屬性元素(property elements)也可作為屬性(attributes)來被定義(取代元素):

<?xml version="1.0"?>

<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cd="http://www.recshop.fake/cd#">

<rdf:Description
rdf:about="http://www.recshop.fake/cd/Empire Burlesque"
cd:artist="Bob Dylan" cd:country="USA"
cd:company="Columbia" cd:price="10.90"
cd:year="1985" />

</rdf:RDF>


屬性(property)來定義屬性(attribute)

屬性元素(property elements)也可作為屬性(attributes)來被定義(取代元素):

<?xml version="1.0"?>

<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cd="http://www.recshop.fake/cd#">

<rdf:Description
rdf:about="http://www.recshop.fake/cd/Empire Burlesque">
<cd:artist rdf:resource="http://www.recshop.fake/cd/dylan" />
...
...
</rdf:Description>

</rdf:RDF>

上面的例子中,屬性artist 沒有值,但是卻引用了一個對包含有關藝術家的信息的資源。