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#">
.
. 描述內容請在此處
.
</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)

Elemen atribut (property elements) juga dapat ditakrifkan sebagai atribut (attributes) untuk menggantikan elemen:

<?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>

Pengdefinian Sumber Atribut

Elemen atribut (property elements) juga dapat ditakrifkan sebagai sumber (resources):

Dalam contoh di atas, atribut artist tidak memiliki nilai, tetapi merujuk kepada sumber yang mengandungi informasi tentang artis.

<?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>