- Sams Teach Yourself XML in 21 Days, Third Edition
- Table of Contents
- About the Author
- Acknowledgments
- We Want to Hear from You!
- Introduction
- Part I: At a Glance
- Day 1. Welcome to XML
- All About Markup Languages
- All About XML
- Looking at XML in a Browser
- Working with XML Data Yourself
- Structuring Your Data
- Creating Well-Formed XML Documents
- Creating Valid XML Documents
- How XML Is Used in the Real World
- Online XML Resources
- Summary
- Q&A
- Workshop
- Day 2. Creating XML Documents
- Choosing an XML Editor
- Using XML Browsers
- Using XML Validators
- Creating XML Documents Piece by Piece
- Creating Prologs
- Creating an XML Declaration
- Creating XML Comments
- Creating Processing Instructions
- Creating Tags and Elements
- Creating CDATA Sections
- Handling Entities
- Summary
- Q&A
- Workshop
- Day 3. Creating Well-Formed XML Documents
- What Makes an XML Document Well-Formed?
- Creating an Example XML Document
- Understanding the Well-Formedness Constraints
- Using XML Namespaces
- Understanding XML Infosets
- Understanding Canonical XML
- Summary
- Q&A
- Workshop
- Day 4. Creating Valid XML Documents: DTDs
- All About DTDs
- Validating a Document by Using a DTD
- Creating Element Content Models
- Commenting a DTD
- Supporting External DTDs
- Handling Namespaces in DTDs
- Summary
- Q&A
- Workshop
- Declaring Attributes in DTDs
- Day 5. Handling Attributes and Entities in DTDs
- Specifying Default Values
- Specifying Attribute Types
- Handling Entities
- Summary
- Q&A
- Workshop
- Day 6. Creating Valid XML Documents: XML Schemas
- Using XML Schema Tools
- Creating XML Schemas
- Dissecting an XML Schema
- The Built-in XML Schema Elements
- Creating Elements and Types
- Specifying a Number of Elements
- Specifying Element Default Values
- Creating Attributes
- Summary
- Q&A
- Workshop
- Day 7. Creating Types in XML Schemas
- Restricting Simple Types by Using XML Schema Facets
- Creating XML Schema Choices
- Using Anonymous Type Definitions
- Declaring Empty Elements
- Declaring Mixed-Content Elements
- Grouping Elements Together
- Grouping Attributes Together
- Declaring all Groups
- Handling Namespaces in Schemas
- Annotating an XML Schema
- Summary
- Q&A
- Workshop
- Part I. In Review
- Well-Formed Documents
- Valid Documents
- Part II: At a Glance
- Day 8. Formatting XML by Using Cascading Style Sheets
- Our Sample XML Document
- Introducing CSS
- Connecting CSS Style Sheets and XML Documents
- Creating Style Sheet Selectors
- Using Inline Styles
- Creating Style Rule Specifications in Style Sheets
- Summary
- Q&A
- Workshop
- Day 9. Formatting XML by Using XSLT
- Introducing XSLT
- Transforming XML by Using XSLT
- Writing XSLT Style Sheets
- Using <xsl:apply-templates>
- Using <xsl:value-of> and <xsl:for-each>
- Matching Nodes by Using the match Attribute
- Working with the select Attribute and XPath
- Using <xsl:copy>
- Using <xsl:if>
- Using <xsl:choose>
- Specifying the Output Document Type
- Summary
- Q&A
- Workshop
- Day 10. Working with XSL Formatting Objects
- Introducing XSL-FO
- Using XSL-FO
- Using XSL Formatting Objects and Properties
- Building an XSL-FO Document
- Handling Inline Formatting
- Formatting Lists
- Formatting Tables
- Summary
- Q&A
- Workshop
- Part II. In Review
- Using CSS
- Using XSLT
- Using XSL-FO
- Part III: At a Glance
- Day 11. Extending HTML with XHTML
- Why XHTML?
- Writing XHTML Documents
- Validating XHTML Documents
- The Basic XHTML Elements
- Organizing Text
- Formatting Text
- Selecting Fonts: <font>
- Comments: <!-->
- Summary
- Q&A
- Workshop
- Day 12. Putting XHTML to Work
- Creating Hyperlinks: <a>
- Linking to Other Documents: <link>
- Handling Images: <img>
- Creating Frame Documents: <frameset>
- Creating Frames: <frame>
- Creating Embedded Style Sheets: <style>
- Formatting Tables: <table>
- Creating Table Rows: <tr>
- Formatting Table Headers: <th>
- Formatting Table Data: <td>
- Extending XHTML
- Summary
- Q&A
- Workshop
- Day 13. Creating Graphics and Multimedia: SVG and SMIL
- Introducing SVG
- Creating an SVG Document
- Creating Rectangles
- Adobe's SVG Viewer
- Using CSS Styles
- Creating Circles
- Creating Ellipses
- Creating Lines
- Creating Polylines
- Creating Polygons
- Creating Text
- Creating Gradients
- Creating Paths
- Creating Text Paths
- Creating Groups and Transformations
- Creating Animation
- Creating Links
- Creating Scripts
- Embedding SVG in HTML
- Introducing SMIL
- Summary
- Q&A
- Workshop
- Day 14. Handling XLinks, XPointers, and XForms
- Introducing XLinks
- Beyond Simple XLinks
- Introducing XPointers
- Introducing XBase
- Introducing XForms
- Summary
- Workshop
- Part III. In Review
- Part IV: At a Glance
- Day 15. Using JavaScript and XML
- Introducing the W3C DOM
- Introducing the DOM Objects
- Working with the XML DOM in JavaScript
- Searching for Elements by Name
- Reading Attribute Values
- Getting All XML Data from a Document
- Validating XML Documents by Using DTDs
- Summary
- Q&A
- Workshop
- Day 16. Using Java and .NET: DOM
- Using Java to Read XML Data
- Finding Elements by Name
- Creating an XML Browser by Using Java
- Navigating Through XML Documents
- Writing XML by Using Java
- Summary
- Q&A
- Workshop
- Day 17. Using Java and .NET: SAX
- An Overview of SAX
- Using SAX
- Using SAX to Find Elements by Name
- Creating an XML Browser by Using Java and SAX
- Navigating Through XML Documents by Using SAX
- Writing XML by Using Java and SAX
- Summary
- Q&A
- Workshop
- Day 18. Working with SOAP and RDF
- Introducing SOAP
- A SOAP Example in .NET
- A SOAP Example in Java
- Introducing RDF
- Summary
- Q&A
- Workshop
- Part IV. In Review
- Part V: At a Glance
- Day 19. Handling XML Data Binding
- Introducing DSOs
- Binding HTML Elements to HTML Data
- Binding HTML Elements to XML Data
- Binding HTML Tables to XML Data
- Accessing Individual Data Fields
- Binding HTML Elements to XML Data by Using the XML DSO
- Binding HTML Tables to XML Data by Using the XML DSO
- Searching XML Data by Using a DSO and JavaScript
- Handling Hierarchical XML Data
- Summary
- Q&A
- Workshop
- Day 20. Working with XML and Databases
- XML, Databases, and ASP
- Storing Databases as XML
- Using XPath with a Database
- Introducing XQuery
- Summary
- Q&A
- Workshop
- Day 21. Handling XML in .NET
- Creating and Editing an XML Document in .NET
- From XML to Databases and Back
- Reading and Writing XML in .NET Code
- Using XML Controls to Display Formatted XML
- Creating XML Web Services
- Summary
- Q&A
- Workshop
- Part V. In Review
- Appendix A. Quiz Answers
- Quiz Answers for Day 1
- Quiz Answers for Day 2
- Quiz Answers for Day 3
- Quiz Answers for Day 4
- Quiz Answers for Day 5
- Quiz Answers for Day 6
- Quiz Answers for Day 7
- Quiz Answers for Day 8
- Quiz Answers for Day 9
- Quiz Answers for Day 10
- Quiz Answers for Day 11
- Quiz Answers for Day 12
- Quiz Answers for Day 13
- Quiz Answers for Day 14
- Quiz Answers for Day 15
- Quiz Answers for Day 16
- Quiz Answers for Day 17
- Quiz Answers for Day 18
- Quiz Answers for Day 19
- Quiz Answers for Day 20
- Quiz Answers for Day 21
Introducing RDF
RDF is an XML-based language that we use to describe various resources in a standard way. We can use it to describe any resource, but it's most often used to describe documents on the Web. This is how the W3C describes RDF:
- Resource Description Framework (RDF) is a foundation for processing metadata; it provides interoperability between applications that exchange machine-understandable information on the Web. RDF emphasizes facilities to enable automated processing of Web resources. RDF can be used in a variety of application areas; for example: in resource discovery to provide better search engine capabilities, in cataloging for describing the content and content relationships available at a particular Web site, page, or digital library, by intelligent software agents to facilitate knowledge sharing and exchange, in content rating, in describing collections of pages that represent a single logical "document", for describing intellectual property rights of Web pages, and for expressing the privacy preferences of a user as well as the privacy policies of a Web site. RDF with digital signatures will be key to building the "Web of Trust" for electronic commerce, collaboration, and other applications.
As expected, RDF is a W3C recommendation. You can find an overview page at http://www.w3.org/RDF. The RDF model and syntax specification are at http://www.w3.org/TR/REC-rdf-syntax and the RDF schema specification is at http://www.w3.org/TR/rdf-schema. And you can find an RDF primer at http://www.w3.org/TR/rdf-primer. Here's an overview of some RDF resources that are available:
- http://athena.ics.forth.gr:9090/RDF/— A validating RDF parser by ICS-FORTH that is based on Java.
- http://lists.w3.org/Archives/Public/www-rdf-interest/2000May/0009.html— An RDF parser by Dan Connolly that uses XSLT.
- http://nestroy.wi-inf.uni-essen.de/xwmf— The Extensible Web Modeling Framework (XWMF), which includes an RDF parser.
- http://www.w3.org/RDF/Validator— A simple RDF validator on the W3C site.
- http://www.w3.org/Library/src/HTRDF— John Punin's RDF parser, which is written in C.
- http://www710.univ-lyon1.fr/~champin/rdf-tutorial— An RDF tutorial online. (It's in English, even though the Web page is French.)
No major browser has a lot of built-in RDF support right now. Mozilla, Netscape Navigator's open-source test version, has some RDF support built into it. If you want to learn more, take a look at these documents:
- http://www.mozilla.org/rdf/50-words.html— An overview of RDF and how it fits with Mozilla.
- http://www.mozilla.org/rdf/doc/faq.html— The RDF Mozilla FAQ, which also includes a little sample code.
- http://www.mozilla.org/rdf/doc/datasource-howto.html— A cookbook that shows how to create RDF data sources.
- http://www.mozilla.org/rdf/rdf-nglayout.html— A document that describes how to use RDF in Mozilla.
- http://www.mozilla.org/rdf/doc/api.html— A technical overview of the Mozilla RDF implementation.
- http://www.mozilla.org/rdf/doc/SmartBrowsing.html— A page that describes Mozilla's SmartBrowsing system, which allows third-party metadata servers to provide RDF related-link annotations. SmartBrowsing is one of the first true uses of RDF for indexing Web resources on a large scale.
Internet Explorer lags behind Mozilla, although Microsoft does have an RDF viewer available for free. You can find it at (as of this writing) http://msdn.microsoft.com/downloads/samples/Internet/xml/xml_rdf_viewer/sample.asp. This viewer can read RDF documents and display the data in them—but note that to run the viewer, you need Internet Explorer 5.0 or later, Visual Basic 6.0, and Windows 98, Windows NT 4.0, or Windows 2000.
What do RDF documents look like? Here's an example of an RDF document that describes the stoic philosopher Epictetus as the creator of a certain resource, which, let's say, is to be found at the (fictitious) URI http://www.XMLPowerCorp.com/philosophy.html:
<?xml version="1.0" encoding="UTF-8"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdf:Description about="http://www.XMLPowerCorp.com/philosophy.html"> <Creator>Epictetus</Creator> </rdf:Description> </rdf:RDF>
RDF is a very general language. In fact, the <Creator> element does not exist in standard RDF. However, there are many sublanguages built on RDF, such as one called the Dublin Core. The <Creator> element is part of the Dublin Core, which means that Web search engines that support the Dublin Core know enough to search for <Creator> elements when they want to find a particular Web resource's author.
We'll start working with RDF by seeing what the rules are.
Understanding How RDF Documents Work
In general, RDF documents are made of RDF statements, each of which has three parts, making each statement a triple. Here are the three parts of an RDF statement:
- A resource— A resource is typically a Web document that we point to with a URI.
- A named property— A named property is a characteristic or an attribute of the resource, such as the resource's creator.
- A property value— The property value is the property's content. For example, the value of the <Creator> property is often the name of the resource's creator.
In RDF the resource is called the subject of the statement, the named property is called the predicate of the statement, and the property value is called the object of the statement. In the following simple RDF document:
<?xml version="1.0" encoding="UTF-8"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdf:Description about="http://www.XMLPowerCorp.com/philosophy.html"> <Creator>Epictetus</Creator> </rdf:Description> </rdf:RDF>
the subject is the document http://www.XMLPowerCorp.com/philosophy.html, the predicate is the named property Creator, and the object is the name of the document's creator, Epictetus. We'll take this document apart in detail now.
Creating RDF Root Elements
RDF documents are XML documents, of course, so start each one with an XML declaration. The root element is <RDF>:
<?xml version="1.0" encoding="UTF-8"?> <RDF . . . </RDF>
RDF documents must use the RDF namespace setting, which is "http://www.w3.org/1999/02/22-rdf-syntax-ns#". (The # on the end, which might look odd, is not an error; the idea is that it can help applications create XPointers.) The usual prefix for this namespace is rdf, and you'll use that here:
<?xml version="1.0" encoding="UTF-8"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> . . . </rdf:RDF>
Creating Description Elements
When you describe a resource, it gets its own <rdf:Description> element. Here are the attributes you can use with this element:
- about — Specifies what resource the element describes.
- aboutEach — Specifies statements about each of the element's children.
- aboutEachPrefix — Specifies RDF container items, by prefix.
- bagID — Specifies the ID of an associated bag container.
- ID — Gives the element an ID value.
- type — Specifies the description's type.
In this example, the resource you are describing is http://www.XMLPowerCorp.com/philosophy.html, so assign that URI to the about attribute of the <rdf:Description> element:
<?xml version="1.0" encoding="UTF-8"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdf:Description about="http://www.XMLPowerCorp.com/philosophy.html"> . . . </rdf:Description> </rdf:RDF>
To store the actual description of the resource, we use property elements, which are described next.
Creating Property Elements
The <rdf:Description> element contains the elements that contain the actual description. For example, for the document you're describing, you can use a <Creator> element:
<?xml version="1.0" encoding="UTF-8"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdf:Description about="http://www.XMLPowerCorp.com/philosophy.html"> <Creator>Epictetus</Creator> </rdf:Description> </rdf:RDF>
There are no properties, like Creator, built into RDF, per se. We can create whatever properties we like. There are a number of RDF applications already available, however, and the most popular and well supported of these is the Dublin Core. You'll take a look at it next—and it does have a <Creator> element built into it.
Using the Dublin Core
All the details about the Dublin Core are available at http://dublincore.org/. The Dublin Core provides a set of elements for use in RDF, and it is being used in many places—government agencies, libraries, corporations, on the Web. The Dublin Core calls itself a "metadata initiative," and it's a strongly supported concern; you'll find frequent updates to what's going on at its Web site.
The Dublin Core namespace setting is "http://purl.org/DC/" (note that this namespace is usually associated with the prefix dc). You should use this namespace setting if you're going to use the Dublin Core. Here's how that looks in our RDF example:
<?xml version="1.0" encoding="UTF-8"?> <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.XMLPowerCorp.com/philosophy.html"> <dc:Creator>Epictetus</dc:Creator> </rdf:Description> </rdf:RDF>
Besides <Creator>, there are plenty of other elements in the Dublin Core, as listed in Table 18.1.
Table 18.1. The Dublin Core Elements
Element |
What It Means |
Contributor |
A person or an organization that has contributed to this resource. |
Coverage |
The extent or scope of the resource. |
Creator |
Usually refers to the resource's author. |
Date |
A date connected to the resource, such as its last update or its creation date. It uses the YYYY-MM-DD format. |
Description |
A description of the resource. |
Format |
The format used for the resource. It is usually a MIME type. |
Identifier |
An ID value for the resource in its context. |
Language |
The language of the resource. It uses values defined by RFC 1766 and includes a two-letter language code with an optional two-letter country code (from the ISO 3166 standard), such as "en-us". |
Publisher |
The entity responsible for the resource. |
Relation |
A reference to a related resource or relationship type. |
Rights |
Rights information for the resource. |
Source |
The source from which the current resource is derived. |
Subject |
The topic of the content of the resource. |
Title |
A name given to the resource. |
Type |
The content type of the resource. |
Also, each of the Dublin Core elements has 10 attributes:
- Comment — Provides a comment about the use of the data in the element.
- Datatype — Specifies the type of data in the element.
- Definition — Defines the concept behind the data in the element.
- Identifier — Specifies a unique identifier assigned to the element that identifies it.
- Language — Specifies the language of the data in the element.
- Maximum Occurrence — Puts a limit on how many times the element may occur.
- Name — Specifies the name assigned to the data element.
- Obligation — Specifies whether the element is required.
- Registration Authority — Refers to the agency or group authorized to register the element.
- Version — Specifies the version of the element.
Six of these attributes have fixed values:
- Version — 1.1
- Registration Authority — Dublin Core Metadata Initiative
- Language — en (that is, English)
- Obligation — Optional
- Datatype — Character String
- Maximum Occurrence — Unlimited
In addition, the Dublin Core also lists a set of default resource types that we can use with the <Type> element:
- collection
- dataset
- event
- image
- interactive resource
- model
- party
- physical object
- place
- service
- software
- sound
- text
Up to this point, you've only used one property, Creator, to describe the resource, but you can use multiple resources at the same time. For example, Listing 18.7 shows an example of an RDF document that uses multiple properties to describe a single resource.
Example 18.7. An RDF Example (ch18_07.rdf)
<?xml version="1.0" encoding="UTF-8"?> <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.XMLPowerCorp.com/philosophy.html"> <dc:Creator>Epictetus</dc:Creator> <dc:Description>The stoic philosopher's teachings</dc:Description> <dc:Title>The Discourses</dc:Title> <dc:Type>text</dc:Type> </rdf:Description> </rdf:RDF>
Working with Multiple Resources
Besides using multiple properties for each description, you can also use one single RDF document to describe multiple resources; in this case, each description has its own <rdf:Description> element. Listing 18.8 shows an example that describes various chapters from Book III of Epictetus' Discourses.
Example 18.8. An RDF Example That Describes Multiple Resources (ch18_08.rdf)
<?xml version="1.0" encoding="UTF-8"?> <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.XMLPowerCorp.com/chapter1.html"> <dc:Creator>Epictetus</dc:Creator> <dc:Language>en</dc:Language> <dc:Title>Of personal adornment</dc:Title> <dc:Type>text</dc:Type> </rdf:Description> <rdf:Description about="http://www.XMLPowerCorp.com/chapter2.html"> <dc:Creator>Epictetus</dc:Creator> <dc:Language>en</dc:Language> <dc:Title>The fields of study</dc:Title> <dc:Type>text</dc:Type> </rdf:Description> <rdf:Description about="http://www.XMLPowerCorp.com/chapter3.html"> <dc:Creator>Epictetus</dc:Creator> <dc:Language>en</dc:Language> <dc:Title>What is the subject-matter?</dc:Title> <dc:Type>text</dc:Type> </rdf:Description> </rdf:RDF>
We can also nest RDF descriptions. For example, if we want to describe three chapters of Epitectus' Book III by using nested RDF, we just have to nest <rdf:Resource> elements appropriately. Listing 18.9 shows how this works.
Example 18.9. A Nested RDF Example (ch18_09.rdf)
<?xml version="1.0" encoding="UTF-8"?> <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.XMLPowerCorp.com/bookIII.html"> <dc:Title>Book III</dc:Title> <dc:Creator>Epictetus</dc:Creator> <rdf:Description about="http://www.XMLPowerCorp.com/chapter1.html"> <dc:Creator>Epictetus</dc:Creator> <dc:Language>en</dc:Language> <dc:Title>Of personal adornment</dc:Title> <dc:Type>text</dc:Type> </rdf:Description> <rdf:Description about="http://www.XMLPowerCorp.com/chapter2.html"> <dc:Creator>Epictetus</dc:Creator> <dc:Language>en</dc:Language> <dc:Title>The fields of study</dc:Title> <dc:Type>text</dc:Type> </rdf:Description> <rdf:Description about="http://www.XMLPowerCorp.com/chapter3.html"> <dc:Creator>Epictetus</dc:Creator> <dc:Language>en</dc:Language> <dc:Title>What is the subject-matter?</dc:Title> <dc:Type>text</dc:Type> </rdf:Description> </rdf:Description> </rdf:RDF>
Using Resource Attributes
In RDF, there's another valid way of referring to a resource that a property describes: using the rdf:resource attribute. Listing 18.10 shows an example that uses this attribute to tie various RDF elements to the resources they describe.
Example 18.10. An RDF Resource Attribute Example (ch18_10.rdf)
<?xml version="1.0" encoding="UTF-8"?> <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.XMLPowerCorp.com/chapter1.html"> <dc:Title>Chapter 1</dc:Title> <dc:Creator rdf:resource="http://www.XMLPowerCorp.com/epictetus.html"/> </rdf:Description> <rdf:Description about="http://www.XMLPowerCorp.com/chapter2.html"> <dc:Title>Chapter 2</dc:Title> <dc:Creator rdf:resource="http://www.XMLPowerCorp.com/epictetus.html"/> </rdf:Description> <rdf:Description about="http://www.XMLPowerCorp.com/chapter3.html"> <dc:Title>Chapter 3</dc:Title> <dc:Creator rdf:resource="http://www.XMLPowerCorp.com/epictetus.html"/> </rdf:Description> </rdf:RDF>
Using the rdf:resource attribute is a shortcut way to connect a resource to an RDF that makes such a connection easy to implement.
Using XML in RDF Elements
It's not uncommon to use XML inside RDF elements to store data. Unfortunately, although we can set the Type property to "text", there is no official "xml" setting for this property. Instead, we can set up our software to treat the XML data as XML. As far as RDF is concerned, we can set the parseType attribute of the property to "Literal", as shown in Listing 18.11.
Example 18.11. A Nested RDF Example (ch18_11.rdf)
<?xml version="1.0" encoding="UTF-8"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://www.purl.org/DC/" xmlns:nsp="http://www.XMLPowerCorp.com/namespace/"> <rdf:Description about="http://www.XMLPowerCorp.com/philosophy.html"> <dc:Creator parseType="Literal"> <nsp:name>Epictetus</nsp:name> <nsp:occupation>Philosopher</nmp:occupation> <nsp:type>Stoic</nsp:type> <nsp:locale>Italy</nsp:locale> </dc:Creator> </rdf:Description> </rdf:RDF>
Another way of doing this is to use the Dublin Core <Format> element and use an XML MIME type, like this:
<?xml version="1.0" encoding="UTF-8"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://www.purl.org/DC/" xmlns:nsp="http://www.XMLPowerCorp.com/namespace/"> <rdf:Description about="http://www.XMLPowerCorp.com/philosophy.html"> <dc:Format>application/xml</dc:Format> <dc:Creator parseType="Literal"> <nsp:name>Epictetus</nsp:name> <nsp:occupation>Philosopher</nmp:occupation> <nsp:type>Stoic</nsp:type> <nsp:locale>Italy</nsp:locale> </dc:Creator> </rdf:Description> </rdf:RDF>
Using Abbreviated RDF
There's also an abbreviated RDF syntax that can make writing RDF documents easier. When we abbreviate RDF, we just change property elements into attributes of the <rdf:Description> element. Say, for example, that you have this RDF document:
<?xml version="1.0" encoding="UTF-8"?> <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.XMLPowerCorp.com/chapter1.html"> <dc:Creator>Epictetus</dc:Creator> <dc:Language>en</dc:Language> <dc:Title>Chapter 1</dc:Title> <dc:Type>text</dc:Type> </rdf:Description> <rdf:Description about="http://www.XMLPowerCorp.com/chapter2.html"> <dc:Creator>Epictetus</dc:Creator> <dc:Language>en</dc:Language> <dc:Title>Chapter 2</dc:Title> <dc:Type>text</dc:Type> </rdf:Description> . . .
You could abbreviate the RDF this way:
<?xml version="1.0" encoding="UTF-8"?> <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.XMLPowerCorp.com/chapter1.html"> dc:Creator = "Epictetus" dc:Language = "en" dc:Title = "Chapter 1" dc:Type = "text"> </rdf:Description> <rdf:Description about="http://www.XMLPowerCorp.com/chapter2.html"> dc:Creator = "Epictetus"> dc:Language = "en" dc:Title = "Chapter 2" dc:Type = "text"> </rdf:Description> . . .
This type of abbreviating can be especially useful with RDF that is embedded in an HTML document because HTML browsers convert elements they don't understand into simple text. If we want to hide RDF data, we can put that data into attributes, not RDF elements, because the data in the attributes won't be shown.