RxML 1.0 |
- Introduction
- rx:prefixes
- rx:resource
- Literal elements
- Lists
- Blank nodes.
- Statement Identifiers
- Resource types and classes.
- Advanced example.
- Comparison between RxML and RDF/XML
- RELAX NG Compact Schema for RxML
Introduction
RxML is an alternative XML serialization for RDF that is designed for easy and simple authoring, particularly in conjunction with ZML. This document is intended as an informal but comprehensive description of RxML. ZML is alternative syntax for XML, enabling us to specify RxML in terms of XML, even though RxML is designed to be expressed as ZML.
The structure of a RxML docment is simple: each child of the root rx element represent a resource. Each child element of the resource element specifies a name-value pair that applies to the resource. Together the resource and name-value pair form a RDF statement.
Any element name that is not part of RXML namespace (conventially represented as 'rx') is converted to a URI reference as specified by RxPath -- basically, the local name is appended to the namespace URI. These URI references are treated as the RDF URI reference for the element. In RDF, both resources and property names are given URI references (actually, a property name is a resource).
Here's a simple example:
<rx xmlns:rx='http://rx4rdf.sf.net/ns/rxml#'
xmlns:mysite='http://example.org/mysite/'
xmlns:dc="http://purl.org/dc/elements/1.1/" >
<mysite:page1.html>
<dc:author>me</dc:author>
<dc:title>The first page</dc:title>
<dc:relatedTo><mysite:lastPage.html/></dc:relatedTo>
</mysite:page1>
<mysite:lastPage.html>
<dc:author>me</dc:author>
<dc:title>The last page</dc:title>
<dc:relatedTo><mysite:page1.html/></dc:relatedTo>
</mysite:lastPage.html>
</rx>
The value of a property can be either literal text or a resource, represented by a resource element -- notice that the value of the 'relatedTo' property in the example above). If the property element has no children, it assumed its value is an empty literal. The value of a properties can also be a list of literals or resources -- see the section on lists below.
rx:prefixes
You can use the rx:prefixes element to declare prefixes instead of using namespace declarations:
<rx>
<prefixes>
<mysite>http://example.org/mysite/</mysite>
<dc>http://purl.org/dc/elements/1.1/</dc>
<default-ns>http://rx4rdf.sf.net/ns/rxml#</default-ns>
</prefixes>
....
</rx>
The default-ns child element is equivalent to the "xmlns" attribute for declaring the "default" namespace for non-prefixed element names.
This is convenient for writing RxML in ZML. Here is the first example again, written in ZML and using rx:prefixes:
rx:
prefixes:
default-ns: `http://rx4rdf.sf.net/ns/rxml#
mysite: `http://example.org/mysite/
dc: `http://purl.org/dc/elements/1.1/
mysite:page1.html:
dc:author: `me
dc:title: `The first Page
dc:relatedTo:
mysite:lastPage.html
mysite:lastPage.html:
dc:author: `me
dc:title: `The last Page
dc:relatedTo:
mysite:page1.html
Technical note: if the RxML document is encoded in XML and it contains rx:prefixes element it must include, in the root element, namespace declarations corresponding exactly to all the prefixes declared in the rx:prefixes element. This is to ensure that namespace-aware XML processors can handle the RxML document properly.
rx:resource
Sometimes it is not convenient to map an URL to an element name. In that case, you can use rx:resource, which has an id attribute whose value is the URI reference of the resource. For example, in the example above the <mysite:page1.html> element could haven been replaced with: <resource id="http://example.org/mysite/page1.html">. If the id attribute is missing or has an empty value, the resource is treated as a blank node. Note that in ZML expanded form of a QName can be written directly as a URI wrapped in "{}", so this form is not needed when expressing RxML in ZML; for example, the above example can be replaced with {http://example.org/mysite/page1.html}.
Literal elements
If the child of a property element is an element named "rx:xml" the value of the property is the XML contained in that rx:xml element (and, in RDF terms, is treated as an XML literal). If the child of a property element is an element named "rx:l" the value of the property is the literal text contained in that rx:l element. A rx:l element can only contain text, but may have two optional attributes: the xml:lang attribute whose value declares the language of the literal, and rdf:datatype whose value is a datatype URI reference that declares the datatype of the literal.
Lists
In addition to literal and resource names, value of a property can also be a list of resources and/or literals. In this case, the property element will have multiple children elements or may have a list attribute. The value of the list is a URI reference naming the list or maybe an empty string (in which case the list resource is treated as a blank node). In addition to naming the list, the list attribute can be used to indicate a property with one or zero child elements actually has value that is a list with one or zero items. A property element may also have a listType attribute whose value is one of rdf:List (the default), rdf:Seq, rdf:Bag, or rdf:Alt, which indicates the type of list (and also indicates the existence of a list in the case of one or no children). If an item in a list is a literal it must indicated using a rx:l or rx:xml element -- raw text is not valid in lists.
Note that property that has a list of values is not that same as multiple identical properties each with a value. For example, this snippet:
myresource: author: `john author: `betty
results in different RDF statements than this:
myresource:
authors:
rx:l: `john
rx:l: `betty
Blank nodes.
Blank nodes are designated by a resource whose URI reference that begins with "bnode:". The portion of the URI after this serves as the identifier for the node. Conventionally (and obviously), the "bnode" prefix is associated with the bnode: URI. Also, a rx:resource element without an id attribute (or an id with an empty value) is treated as a blank node.
Below is example of a typical usage of blank nodes:
rx:
prefixes:
a: `http://rx4rdf.sf.net/ns/archive#
wiki: `http://rx4rdf.sf.net/ns/wiki#
bnode: `bnode:
default-ns: `http://rx4rdf.sf.net/ns/rxml#
resource id='mailto:omaas@example.com':
name: `Oedipa Maas
address:
bnode:address1
bnode:address1:
street: `123 1st street
city: `San Narcisco
state: `CA
postalcode: `94110
country: `USA
Statement Identifiers
An individual statement (a declaration of a property value pair for a particular resource) can be turned into a resource itself by giving it an identifier (in RDF, this is called reification). This is done when the rx:stmtID attribute appears on a property element. The value of rx:stmtID is a URI reference. Reification is useful when you want to attach metadata about the statement itself, for example, to say this asserted by whom or asserted on this data, etc.
Resource types and classes.
RxML provides rx:a element which can be used as a synonym for the rdf:type property, providing a concise way to express the type of a resource. For example, the following example declares a resource of type "wiki:Item":
rx:
prefixes:
wiki: `http://rx4rdf.sf.net/ns/wiki#
bnode: `bnode:
default-ns: `http://rx4rdf.sf.net/ns/rxml#
bnode:blankNode1:
a: wiki:Item
Advanced example.
Below is an example written in ZML that demonstrates all the features of RxML.
rx:
prefixes:
wiki: `http://rx4rdf.sf.net/ns/wiki#
bnode: `bnode:
#note: not necessary since default-ns defaults to this
default-ns: `http://rx4rdf.sf.net/ns/rxml#
bnode:blankNode1:
a: wiki:NamedContent
wiki:last-modified:
#by placing a literal value inside a "l" element
#you can declare a datatype or xml:lang for it
l rdf:datatype="http://www.w3.org/2001/XMLSchema#integer":
"1062022787"
#stmtID is equivalent to "rdf:ID"
wiki:name stmtID='http://rx4rdf.sf.net/ns/archive#': `foo
#properties with multiple values are treated as lists
#the list and listType attributes are optional
wiki:revisions listType='rdf:Bag' list="bnode:list57":
{http://example.org/mysite/page1.html}
l xml:lang=en: `some text in english
#the property value is the markup inside the "xml"
xml:
html:
body:
r"some <b>xml</b> content"
Comparison between RxML and RDF/XML
The biggest differences between RxML and RDF/XML are:
- The name of a resource element does not specify the type of the resource, as in RDF/XML, but rather the URI of the resource itself.
- RxML does not support striped syntax -- the object element of a property can not have any children.
- There are no alternative syntax shortcuts such as empty property elements (rdf:resource) and property attributes.
RELAX NG Compact Schema for RxML
# RELAX NG Compact Schema for RxML
namespace local = ""
namespace rx = "http://rx4rdf.sf.net/ns/rxml#"
namespace rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
start = doc
doc = element rx:rx {
prefixesElement?, (resourceElement* & subjectResourceElement* & resQueryElement)
}
prefixesElement = element rx:prefixes { prefixesChildElement* }
#any QName except if in the rx namespace (except for rx:default-ns)
prefixesChildElement = element * - (local:* | rx:*) | rx:default-ns { URI-reference }
#any QName except if in the rx namespace
resourceElement = element * - (local:* | rx:*) {
propertyElement* & propertyResourceElement*
}
subjectResourceElement = element rx:resource {
resourceIdAttribute,
propertyElement* & propertyResourceElement*
}
resQueryElement = element rx:res-query {
attribute select { text },
propertyElement* & propertyResourceElement*
}
resourceIdAttribute = attribute id { URI-reference }?
#rx:a or any QName except if in the rx namespace
propertyElement = element (* - (local:* | rx:*)) | rx:a {
propertyAttribute*,
text | propertyValueElement*
}
propertyResourceElement = element rx:resource {
resourceIdAttribute,
propertyAttribute*,
text | propertyValueElement*
}
propertyAttribute = attribute rx:list | list | rx:stmtID | stmtID { URI-reference }
| attribute rx:listType | listType {
"rdf:List" | "rdf:Seq" | "rdf:Bag" | "rdf:Alt"
}
propertyValueElement = objectResourceElement | rx:resource { resourceIdAttribute }
| literalElement | xmlLiteralElement
#any QName except if in the rx namespace
objectResourceElement = element * - (local:* | rx:*) {}
literalElement = element rx:l {
attribute rdf:Datatype {URI-reference }?,
attribute xml:lang { text }?,
text
}
xmlLiteralElement element rx:xml { any }
URI-reference = text
any = mixed { element * { attribute * { text }*, any }* }

