RDF 的主要元素是 <RDF> 以及可表示某個資源的 <Description> 元素。
RDF 主要元素
<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 elements)也可被作為資源(resources)來被定義:
在上面的例子中,屬性 artist 沒有值,但是卻引用了一個對包含有關藝術家的信息的資源。
<?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>