RDF also enables you to group properties together by defining property containers. Three containers exist:
These containers are supported with the <rdf:Bag>, <rdf:Seq>, and <rdf:Alt> elements, which have ID and aboutEach attributes. (The W3C RDF syntax specification mistakenly defines these elements with only an ID attribute, but then uses both attributes in the text). I'll use both those attributes in this chapter.
You use a Bag container to indicate that a property has multiple, although unordered, values. How do you specify the multiple items in a container? You use the <rdf:li> element (modeled after the HTML <LI>, list item, element).
Here's an example; in this case, I'm indicating that the planets.html resource has multiple subjects—Mercury, Venus, Mars, and Earth:
<?xml version="1.0" ?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://www.purl.org/DC#"> <rdf:Description about="http://www.starpowder.com/planets.html"> <dc:Title>Planets</dc:Title> <dc:Creator>Nicolas Copernicus</dc:Creator> <dc:Type>text</dc:Type> <dc:Subject> <rdf:Bag> <rdf:li>Mercury</rdf:li> <rdf:li>Venus</rdf:li> <rdf:li>Earth</rdf:li> <rdf:li>Mars</rdf:li> </rdf:Bag> </dc:Subject> </rdf:Description> </rdf:RDF>
The items in a bag can also be resource references, of course, like this:
<?xml version="1.0" ?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://www.purl.org/DC#"> <rdf:Description about="http://www.starpowder.com/planets.html"> <dc:Title>Planets</dc:Title> <dc:Creator>Nicolas Copernicus</dc:Creator> <dc:Subject> <rdf:Bag> <rdf:li rdf:resource="http://www.starpowder.com/mercury.html"/> <rdf:li rdf:resource="http://www.starpowder.com/venus.html"/> <rdf:li rdf:resource="http://www.starpowder.com/earth.html"/> <rdf:li rdf:resource="http://www.starpowder.com/mars.html"/> </rdf:Bag> </dc:Subject> </rdf:Description> </rdf:RDF>
You use a Seq to indicate that a property has multiple ordered values. In this case, you are indicating that the multiple property values have some order. For example, this document indicates that planet.html covers the topics Mercury, Venus, Earth, and Mars, in that order:
<?xml version="1.0" ?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://www.purl.org/DC#"> <rdf:Description about="http://www.starpowder.com/planets.html"> <dc:Title>Planets</dc:Title> <dc:Creator>Nicolas Copernicus</dc:Creator> <dc:Subject> <rdf:Seq> <rdf:li>Mercury</rdf:li> <rdf:li>Venus</rdf:li> <rdf:li>Earth</rdf:li> <rdf:li>Mars</rdf:li> </rdf:Seq> </dc:Subject> </rdf:Description> </rdf:RDF>
The Alt container provides alternatives, such as different language versions of a resource, or mirror sites. In general, you use it to associate alternative resources with a document. Here's an example; in this case, I'm listing various versions of a document in different formats, plain text, HTML, Rich Text Format (RTF), and XML:
<?xml version="1.0" ?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://www.purl.org/DC#"> <rdf:Description about="http://www.starpowder.com/planets"> <dc:Title>Planets</dc:Title> <dc:Creator>Nicolas Copernicus</dc:Creator> <dc:Format> <rdf:Alt> <rdf:li resource = "http://www.starpowder.com/planets.html"> text/html </rdf:li> <rdf:li resource = "http://www.starpowder.com/planets.txt"> text/plain </rdf:li> <rdf:li resource = "http://www.starpowder.com/planets.rtf"> text/rtf </rdf:li> <rdf:li resource = "http://www.starpowder.com/planets.xml"> text/xml </rdf:li> </rdf:Alt> </dc:Format> </rdf:Description> </rdf:RDF>
You can use a container's ID attribute to make a statement about the container as a whole, separate from the items in the container. Here's an example. In this case, I'm giving a creation date for a bag container; to do that, I give the bag container the ID "planets" and then create a new <rdf:Description> element about "#planets" to describe the bag container and give its date:
<?xml version="1.0" ?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://www.purl.org/DC#"> <rdf:Description about="http://www.starpowder.com/planets.html"> <dc:Title>XML Links</dc:Title> <dc:Creator>Nicolas Copernicus</dc:Creator> <dc:Subject> <rdf:Bag ID="planets"> <rdf:li rdf:resource="http://www.starpowder.com/mercury.html"/> <rdf:li rdf:resource="http://www.starpowder.com/venus.html"/> <rdf:li rdf:resource="http://www.starpowder.com/earth.html"/> <rdf:li rdf:resource="http://www.starpowder.com/mars.html"/> </rdf:Bag> </dc:Subject> </rdf:Description> <rdf:Description about="#planets"> <dc:Date> 1501-10-15 </dc:Date> </rdf:Description> </rdf:RDF>
You can also make statements about each item in a container by using the container's aboutEach attribute. For example, suppose that I want to indicate that each item in a bag has the same creation date; in that case, I could assign the value "creationDate" to the bag's aboutEach attribute, and add a new <rdf:Description> element about "#creationDate", like this:
<?xml version="1.0" ?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://www.purl.org/DC#"> <rdf:Description about="http://www.starpowder.com/planets.html"> <dc:Title>Mercury</dc:Title> <dc:Creator>Nicolas Copernicus</dc:Creator> <dc:Subject> <rdf:Bag aboutEach="creationDate"> <rdf:li resource="http://www.starpowder.com/mercury.html"/> <rdf:li resource="http://www.starpowder.com/venus.html"/> <rdf:li resource="http://www.starpowder.com/earth.html"/> <rdf:li resource="http://www.starpowder.com/mars.html"/> </rdf:Bag> </dc:Subject> </rdf:Description> <rdf:Description aboutEach="#creationDate"> <dc:Date> 1501-10-15 </dc:Date> </rdf:Description> </rdf:RDF>
In fact, you can make statements about groups of resources that have the same prefixes (which may or may not be members of one container). For example, say that I want to connect a date with all resources that start with "http://www.starpowder.com/". I can do that with the aboutEachPrefix attribute of <rdf:Description>, like this:
<?xml version="1.0" ?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://www.purl.org/DC#"> <rdf:Description about="http://www.starpowder.com/planets.html"> <dc:Title>Mercury</dc:Title> <dc:Creator>Nicolas Copernicus</dc:Creator> <dc:Subject> <rdf:Bag> <rdf:li resource="http://www.starpowder.com/mercury.html"/> <rdf:li resource="http://www.starpowder.com/venus.html"/> <rdf:li resource="http://www.starpowder.com/earth.html"/> <rdf:li resource="http://www.starpowder.com/mars.html"/> </rdf:Bag> </dc:Subject> </rdf:Description> <rdf:Description aboutEachPrefix="#http://www.starpowder.com/"> <dc:Date> 1501-10-15 </dc:Date> </rdf:Description> </rdf:RDF>
3.147.66.149