Using Abbreviated RDF Syntax

The W3C also defines an abbreviated RDF syntax to make things a little easier. To use the abbreviated syntax, you just convert property elements to attributes of the <rdf:Description> element. For example, here's what an unabbreviated document might look like:

 <?xml version="1.0" ?>  <rdf:RDF     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"     xmlns:dc="http://purl.org/DC/">     <rdf:Description about="http://www.starpowder.com/mercury.html">         <dc:Creator>Nicolas Copernicus</dc:Creator>         <dc:Title>Mercury</dc:Title>         <dc:Type>text</dc:Type>     </rdf:Description>     <rdf:Description about="http://www.starpowder.com/venus.html">         <dc:Creator>Nicolas Copernicus</dc:Creator>         <dc:Title>Venus</dc:Title>         <dc:Type>text</dc:Type>     </rdf:Description>     .     .     . 

Here's the abbreviated form:

 <?xml version="1.0" ?>  <rdf:RDF     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"     xmlns:dc="http://purl.org/DC/">  <rdf:Description about="http://www.starpowder.com/mercury.html"   dc:Creator = "Nicolas Copernicus"   dc:Title = "Mercury"   dc:Type = "text">   </rdf:Description>   <rdf:Description about="http://www.starpowder.com/venus.html"   dc:Creator = "Nicolas Copernicus">   dc:Title = "Venus"   dc:Type = "text">   </rdf:Description>  .     .     . 

Why is this useful? One big reason is that it makes RDF easier to handle in HTML browsers in case that RDF is embedded in an HTML document. Recall that HTML browsers will ignore any tags that they don't understand and simply treat the element's content as plain text. If you convert the property elements to attributes, there are no property elements to be mishandled in that way.

The situation is a little more complex if your properties themselves contain resources. In that case, it's best to refer to those resources by reference using the rdf:resource attribute:

 <?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/mercury.html"         dc:Title = "Mercury">  <dc:Creator rdf:resource="http://www.starpowder.com/NickC.html"/>  </rdf:Description>     <rdf:Description about="http://www.starpowder.com/venus.html"         dc:Title = "Venus">  <dc:Creator rdf:resource="http://www.starpowder.com/NickC.html"/>  </rdf:Description>     .     .     . 

Even though this uses <dc:Creator> property elements, there is still no element content to be treated as plain text by an HTML browser.



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net