| 上一頁(P) | 上一層(T) | 下一頁(N) |
| 5. 正式的資源描述架構模型 | 7. 範例 |
資源描述架構所使用的 BNF 語法已在前一節中完完整整地列了出來,關於模型更精確的語法也在前一節加以解釋了。延伸標記語法的句法功能也不會在這一節解釋,這包含所有延伸標記語言的限制、屬性及等號可以圍繞空白字元、可用單引號或雙引號包圍屬性值…等。這一節是為了那些建立讀寫資、解釋源描述架構/延伸標記語言的語法工具的實作者。
下以用〝 〞包含的關鍵字〝應該〞、〝必需〞、〝不必〞,這些字的解釋可在 RFC 2119[RFC2119]找到解釋。
[6.1] RDF ::= ['<rdf:RDF>'] obj* ['</rdf:RDF>']
[6.2] obj ::= description | container
[6.3] description ::= '<rdf:Description' idAboutAttr? bagIdAttr? propAttr* '/>'
| '<rdf:Description' idAboutAttr? bagIdAttr? propAttr* '>'
propertyElt* '</rdf:Description>'
| typedNode
[6.4] container ::= sequence | bag | alternative
[6.5] idAboutAttr ::= idAttr | aboutAttr | aboutEachAttr
[6.6] idAttr ::= ' ID="' IDsymbol '"'
[6.7] aboutAttr ::= ' about="' URI-reference '"'
[6.8] aboutEachAttr ::= ' aboutEach="' URI-reference '"'
| ' aboutEachPrefix="' string '"'
[6.9] bagIdAttr ::= ' bagID="' IDsymbol '"'
[6.10] propAttr ::= typeAttr
| propName '="' string '"' (with embedded quotes escaped)
[6.11] typeAttr ::= ' type="' URI-reference '"'
[6.12] propertyElt ::= '<' propName idAttr? '>' value '</' propName '>'
| '<' propName idAttr? parseLiteral '>'
literal '</' propName '>'
| '<' propName idAttr? parseResource '>'
propertyElt* '</' propName '>'
| '<' propName idRefAttr? bagIdAttr? propAttr* '/>'
[6.13] typedNode ::= '<' typeName idAboutAttr? bagIdAttr? propAttr* '/>'
| '<' typeName idAboutAttr? bagIdAttr? propAttr* '>'
propertyElt* '</' typeName '>'
[6.14] propName ::= Qname
[6.15] typeName ::= Qname
[6.16] idRefAttr ::= idAttr | resourceAttr
[6.17] value ::= obj | string
[6.18] resourceAttr ::= ' resource="' URI-reference '"'
[6.19] Qname ::= [ NSprefix ':' ] name
[6.20] URI-reference ::= string, interpreted per [URI]
[6.21] IDsymbol ::= (any legal XML name symbol)
[6.22] name ::= (any legal XML name symbol)
[6.23] NSprefix ::= (any legal XML namespace prefix)
[6.24] string ::= (any XML text, with "<", ">", and "&" escaped)
[6.25] sequence ::= '<rdf:Seq' idAttr? '>' member* '</rdf:Seq>'
| '<rdf:Seq' idAttr? memberAttr* '/>'
[6.26] bag ::= '<rdf:Bag' idAttr? '>' member* '</rdf:Bag>'
| '<rdf:Bag' idAttr? memberAttr* '/>'
[6.27] alternative ::= '<rdf:Alt' idAttr? '>' member+ '</rdf:Alt>'
| '<rdf:Alt' idAttr? memberAttr? '/>'
[6.28] member ::= referencedItem | inlineItem
[6.29] referencedItem ::= '<rdf:li' resourceAttr '/>'
[6.30] inlineItem ::= '<rdf:li' '>' value </rdf:li>'
| '<rdf:li' parseLiteral '>' literal </rdf:li>'
| '<rdf:li' parseResource '>' propertyElt* </rdf:li>'
[6.31] memberAttr ::= ' rdf:_n="' string '"' (where n is an integer)
[6.32] parseLiteral ::= ' parseType="Literal"'
[6.33] parseResource ::= ' parseType="Resource"'
[6.34] literal ::= (any well-formed XML)
定義在這份文件中,屬性與類別正式的名稱空間為 http://www.w3.org/1999/02/22-rdf-syntax-ns#。當資源描述架構處理程式遇到一個延伸標記語言的元素或屬性時,而它們的名稱空間為 http://www.w3.org/TR/REC-rdf-syntax,並且處理程式無法辦識名稱的語義,那麼會要求處理程式跳過(像是沒有產生
tuples)整個延伸標記語言的元素,還包含它的內容。它的名稱是無法辦識的或是有個無法辦識的屬性。
Each propertyElt E contained by a Description element results in the creation of a triple {p,r,v} where:
parseType 屬性會改變元素內容的解釋。parseType 屬性的屬性值〝應該〞是 Literal 要不然就是 Resource,記住大小寫有別。屬性值為 Literal 指定元素內容當成資源描述架構/延伸標記語言的文字,內容〝不必〞由資源描述架構處理程式解釋。屬性值為 Resource 指定元素內容〝必需〞當成像是 Description 元素的內容。其它的屬性值則會保留給下一版的資源描述架構的規格書使用。在 資源描述架構 1.0 中,其它的屬性值〝必需〞當成 Literal。在所有的情況下,元素有指定 parseType 屬性的內容〝必需〞符合延伸標記語言的格式。元素有指定 parseType 屬性並且屬性值為 Resource 的內容〝必需〞進一步符合 Descriptoin 元素的內容的限制。
The RDF Model and Syntax Working Group acknowledges that the parseType='Literal' mechanism is a minimum-level solution to the requirement to express an RDF statement with a value that has XML markup. Additional complexities of XML such as canonicalization of whitespace are not yet well defined. Future work of the W3C is expected to resolve such issues in a uniform manner for all applications based on XML. Future versions of RDF will inherit this work and may extend it as we gain insight from further application experience.
經由解析第一個統一資源識別符號的參考而成為絕對的形式[統一資源識別符號](使用文件的基底統一資源識別符號,而這份文件需包含資源描述架構的陳述式),而統一資源識別符號的參考會解析成資源識別符號。如果統一資源識別符號的參考包含片斷識別符號,那麼資源識別符號只會參考所包含資源的子元件,這個字元件是由所包含資源相對應的連結錨識別符號識別。並且子元件的元件是由連接所包含資源的內容型態的片斷識別符號定義,否則資源識別符號會參考整個指定的統一資源識別符號。
注意:儘管在統一資源識別符號中不允許非ASCII字元,在延伸的統一資源識別符號語法中,[延伸標記語言]指定一種方法以避免非必要不相容的問題。鼓勵資源描述架構的實作者避免進一步發生不相容的問題,而對於系統識別符號來說使用延伸標記語法的方法。也就是,統一資源識別符號中如果有非ASCII的字元,可表示成UTF-8的形式,有的字元是一個位元組,有的字元是兩個位元組,然後這些位元組會使用統一資源識別符號的跳脫機制跳脫字元。(像是每個位元組轉換成 %HH,而 HH 是以十六進位制表示位元組的值)。
Description 元素本身可表示成一個 Bag 資源的實例。而這個 Bag 的成員是對應於 Description 元素內陳述式的每個 reification 的資源。如果不是 bagID 屬性的屬性值為這個 Bag 的識別符號,那麼 Bag 即為匿名的。
當 Description 元素指定 about 屬性時,Description 元素內的陳述式 about 屬性所命名的資源。假設 Description 元素沒指定 about 屬性,那麼會表示成行內資源,而這個行內資源有個資源識別符號而形式為:包含資源描述架構陳述式的文件的基底統一資源識別符號加上等同於 Descriptoin 元素的 ID 屬性的屬性值,也就是連結錨識別符號,如果存在的話。當另一個 Description 元素或屬性值參考行內資源,那麼會使用 about 屬性的屬性值當成 ID 屬性的屬性值。當其它的 Description 元素參考 Bag 資源對應於 reified 陳述式,那麼會使用 about 屬性的屬性值當成 bagID 屬性的屬性值。Description 元素可以指定 ID 屬性也可以指定 about 屬性,但是不可同時在一個 Descriptioin 元素中指定這兩個屬性。ID 及 badID 屬性的屬性值〝必需〞在一份文件中是唯一的。
當 Description 元素指定 aboutEach 屬性時,Description 元素的陳述式會參考由 aboutEach 屬性所命名容器的成員。The triples {p,r,v} represented by each contained propertyElt E as described above are duplicated for each r that is a member of the container.
當 Description 元素指定 aboutEachPrefix 屬性時,Description 元素的陳述式會參考匿名 Bag 容器的成員。Bag 容器的成員都是資源,這些資源的絕對形式的資源識別符號是由 aboutEachPrefix 屬性的屬性值起始的。絕對形式的資源識別符號是解析統一資源識別符號產生的(演算法於5.2節有介紹)。在[統一資源識別符號]有說明如何解析相對參考成為絕對形式。The triples {p,r,v} represented by each contained propertyElt E as described above are duplicated for each r that is a member of the container.
Seq、Bag、Alt 每個分別表示 Sequence、Bag、Alternative 容器資源型態的實例。A triple {RDF:type,c,t} is created where c is the collection resource and t is one of RDF:Seq, RDF:Bag, or RDF:Alt. The members of the collection are denoted by li. Each li element E corresponds to one member of the collection and results in the creation of a triple {p,c,v} where:
The URI identifies (after resolution) the target resource; i.e., the resource to which the Description applies or the resource that is included in the container. The bagID attribute on a Description element and the ID attribute on a container element permit that Description or container to be referred to by other Descriptions. The ID on a container element is the name that is used in a resource attribute on a property element to make the collection the value of that property.
Within propertyElt (production [6.12]), the URI used in a resource attribute identifies (after resolution) the resource that is the object of the statement (i.e., the value of this property). The value of the ID attribute, if specified, is the identifier for the resource that represents the reification of the statement. If an RDF expression (that is, content with RDF/XML markup) is specified as a property value the object is the resource given by the about attribute of the contained Description or the (possibly implied) ID of the contained Description or container resource. Strings must be well-formed XML; the usual XML content quoting and escaping mechanisms may be used if the string contains character sequences (e.g. "<" and "&") that violate the well-formedness rules or that otherwise might look like markup. The attribute parseType="Literal" specifies that the element content is an RDF literal. Any markup that is part of this content is included as part of the literal and not interpreted by RDF.
It is recommended that property names always be qualified with a namespace prefix to unambiguously connect the property definition with the corresponding schema.
As defined by XML, the character repertoire of an RDF string is ISO/IEC 10646 [ISO10646]. An actual RDF string, whether in an XML document or in some other representation of the RDF data model, may be stored using a direct encoding of ISO/IEC 10646 or an encoding that can be mapped to ISO/IEC 10646. Language tagging is part of the string value; it is applied to sequences of characters within an RDF string and does not have an explicit manifestation in the data model.
Two RDF strings are deemed to be the same if their ISO/IEC 10646 representations match. Each RDF application must specify which one of the following definitions of 'match' it uses:
Note: The W3C I18N WG is working on a definition for string identity matching. This definition will most probably be based on canonical equivalences according to the Unicode standard and on the principle of early uniform normalization. Users of RDF should not rely on any applications matching using the canonical equivalents, but should try to make sure that their data is in the normalized form according to the upcoming definitions.
This specification does not state a mechanism for determining equivalence between literals that contain markup, nor whether such a mechanism is guaranteed to exist.
The xml:lang attribute may be used as defined by [XML] to associate a language with the property value. There is no specific data model representation for xml:lang (i.e., it adds no triples to the data model); the language of a literal is considered by RDF to be a part of the literal. An application may ignore language tagging of a string. All RDF applications must specify whether or not language tagging in literals is significant; that is, whether or not language is considered when performing string matching or other processing.
Attributes whose names start with "xmlns" are namespace declarations and do not represent triples in the data model. There is no specific data model representation for such namespace declarations.
Each property and value expressed in XML attribute form by productions [6.3] and [6.10] is equivalent to the same property and value expressed as XML content of the corresponding Description according to production [6.12]. Specifically; each XML attribute A specified with a Description start tag other than the attributes ID, about, aboutEach, aboutEachPrefix, bagID, xml:lang, or any attribute starting with the characters xmlns results in the creation of a triple {p,r,v} where:
Grammatically, production [6.11] is just a special case of the propName production [6.10]. The value of the type attribute is interpreted as a URI-reference and expanded in the same way as the value of the resource attribute. Use of [6.11] is equivalent to using rdf:type as an element (property) name together with a resource attribute.
The typedNode form (production [6.13]) may be used to represent instances of resources of specific types and to further describe those resources. A Description expressed in typedNode form by production [6.13] is equivalent to the same Description expressed by production [6.3] with the same ID, bagID, and about attributes plus an additional type property in the Description where the value of the type property is the resource whose identifier is given by the fully expanded and resolved URI corresponding to the typeName of the typedNode. Specifically, a typedNode represents a triple {RDF:type,n,t} where n is the resource whose identifier is given by the value of the about attribute (after resolution) or whose anchor id is given by the value of the ID attribute of the typedNode element, and t is the expansion of the namespace-qualified tag name. The remainder of the typedNode attributes and content is handled as for Description elements above.
Properties and values expressed in XML attribute form within an empty XML element E by productions [6.10] and [6.12] are equivalent to the same properties and values expressed as XML content of a single Description element D which would become the content of E. The referent of D is the value of the property identified by the XML element name of E according to productions [6.17], [6.2], and [6.3]. Specifically; each propertyElt start tag containing attribute specifications other than ID, resource, bagID, xml:lang, or any attribute starting with the characters xmlns results in the creation of the triples {p,r1,r2}, {pa1,r2,va1}, ..., {pan,r2,van} where
The value of the bagID attribute, if specified, is the identifier for the Bag corresponding to the Description D; else the Bag is anonymous.