# XML - Managing Data Exchange/RDF - Resource Description Framework

Author: Sascha Meissner \| Editor: Laura Bashaw\
Editing Status: Draft\
Modification Date: Dec 6, 2004

## Learning objectives

Upon completion of this chapter, you will be able to

-   understand the Resource Description Framework (RDF)
-   use RDF to define metadata for web resources
-   include standards like the Dublin Core for your description
-   explore how Adobe is handling metadata
-   create your own individual properties to expand your description

## Introduction

### Concept

The Resource Description Framework (RDF) is terminology used to encode,
exchange and reuse metadata in the World Wide Web. Metadata, structured
data about data, includes any important type of information about a
resource such as author, title, creation date or language. A
**resource** is everything that can be addressed with a Uniform Resource
Identifier (URI). For
example, a web page or a distinct type of document. RDF considers
**description** as the act of making statements about the properties
(attributes, characteristics) and inter-relationships of these
resources. A **framework** is a common model to contain or manage the
diverse information about a resource.

**Why do we not use XML to describe things?**\
\* XML is too flexible. There are too many ways to describe things. For
example, the name of a person (see code example). Each of these XML
documents would map into a different logical tree. However, a query
,like what is the name of person x, has to be independent of the choice
of the tree. RDF is different because it has a standard way of
interpreting XML-encoded descriptions of resources which converts into
one logical tree and thereby covers all possible reprensentations of a
description.

`<person name="Pete Maravich">`{=html}

or

`<person>`{=html}\
`  ``<name>`{=html}`Pete Maravich``</name>`{=html}\
`</person>`{=html}

-   XML documents follow a schema. The order of elements is restricted,
    and documents are not extensible without changing the schema. RDF
    allows to list information regardless of their order or appearence.
    RDF is also openly extensible. This means if one receives a
    description about something or someone, one can easily add
    information without being limited to following a schema. This is a
    great advantage, particularly for annotation and metadata
    applications. Besides that, it is intricate to retrieve any semantic
    meaning from an XML document without knowing the XML schema.

\
RDF is an application of XML that enforces the needed structural
constraints to provide unambiguous methods of expressing semantics. XML
syntax guarantees vendor independence, extensibility, validation and the
ability to represent complex structures. RDF extends the general XML
syntax and model to be specific for describing resources. Furthermore,
RDF uses XML namespaces that allow to scope and uniquely identify a set
of properties. With namespaces that point to URIs, one can generate
globally unique names for its resources. Unique names need no context to
qualify.

### Brief History

RDF is a result of several metadata communities coming together to build
a robust and flexible architecture for supporting metadata on the
existing web. The first RDF specification was released 1997 by Ora
Lassila and Ralph Swick. Based on that specification RDF interest groups
were established in the following years and RDF became a W3C
recommendation\
(W3C RDF). The potential of RDF was soon
realized and once its use is widespread the impacts will be tremendous.
Ora Lassila said the following
(W3C_NOTE_1997-11-13).

```{=html}
<center>
```
*Once the web has been sufficiently \"populated\" with rich metadata,
what can we expect? First, searching on the web will become easier as
search engines have more information available, and thus searching can
be more focused. Doors will also be opened for automated software agents
to roam the web, looking for information for us or transacting business
on our behalf. The web of today, the vast unstructured mass of
information, may in the future be transformed into something more
manageable - and thus something far more useful.*

```{=html}
</center>
```
### Purpose

Besides the human-readable display of metadata RDF is intended to enable
the exchange of information between different applications without any
loss of meaning. The effective use of metadata among applications,
however, requires common conventions about semantics syntax, and
structure. RDF imposes these conventions that make an unambiguous
transfer possible. Application areas include resource description,
site-maps, content rating, electronic commerce, collaborative services,
and privacy preferences. Earlier one of the major obstacles of metadata
interoperability has been the multiplicity of incompatible standards for
metadata syntax and schema definition languages. However since RDF is a
W3C recommendation and communities provide a standard vocabulary to
describe things application designers and developers can create
applications that allow metadata exchange in a standardized way.

## The Basic Structure

### Statements

With RDF one can make statements about resources. Below you can see an
example of a statement that can be made about a web page. The key parts
of the statement are highlighted:

`<span style="color:blue;">`{=html}http://www.example.org/index.html`</span>`{=html}
has an `<span style="color:red;">`{=html}author`</span>`{=html} whose
name is `<span style="color:darkgreen;">`{=html}Pete
Maravich`</span>`{=html}.

In general a RDF statement is a triple that contains a:

-   `<span style="color:blue;">`{=html}Resource`</span>`{=html}, the
    subject of a statement
-   `<span style="color:red;">`{=html}Property`</span>`{=html}, the
    predicate of a statement
-   `<span style="color:darkgreen;">`{=html}Value`</span>`{=html}, the
    object of a statement

RDF is based on the concept that every resources can have different
properties which have values. A resources, represented by an URI
reference, can be fully described by using properties and their values.
Other properties for this web page could be:

`<span style="color:blue;">`{=html}http://www.example.org/index.html`</span>`{=html}
has a `<span style="color:red;">`{=html}language`</span>`{=html} which
is `<span style="color:darkgreen;">`{=html}English`</span>`{=html}.\
or\
`<span style="color:blue;">`{=html}http://www.example.org/index.html`</span>`{=html}
has a `<span style="color:red;">`{=html}title`</span>`{=html} which is
`<span style="color:darkgreen;">`{=html} Example_Title`</span>`{=html}.

### Graphs

An RDF statement is a structured triple that contains a subject, a
predicate and an object. A set of such triples is called a graph where a
subject is always a node, a predicate is always an arc and an object is
always a node:\
\
!Abstract RDF graph\
`<small>`{=html}**Figure 1 - Abstract RDF graph**`</small>`{=html}\

The set of example statements can be represented by the following graph:

!Example graph\
`<small>`{=html}**Figure 2 - Example graph**`</small>`{=html}

```{=html}
<table width="100%" border="1" cellspacing="0" cellpadding="0">
```
```{=html}
<tr>
```
```{=html}
<td>
```
Subject

```{=html}
</td>
```
```{=html}
<td>
```
<http://www.example.org/index.html>

```{=html}
</td>
```
```{=html}
<td>
```
is either an URI reference or a blank node

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
Predicate

```{=html}
</td>
```
```{=html}
<td>
```
<http://purl.org/dc/elements/1.1/Title>

```{=html}
</td>
```
```{=html}
<td>
```
is an URI reference

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
Object

```{=html}
</td>
```
```{=html}
<td>
```
Example_Title

```{=html}
</td>
```
```{=html}
<td>
```
can either be an URI reference, a literal or a blank node

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
</table>
```
\

### RDF/XML

Natural English sentences and graphs that represent RDF\'s concept model
are very useful pratices to understand the basics of RDF. However RDF
uses a normative XML syntax called RDF/XML to put down and exchange
graphs. Like HTML, RDF/XML is machine processable and, using URIs, can
link pieces of information. But, unlike conventional hypertext, RDF URIs
can refer to any identifiable thing, including things that may not be
directly retrievable on the Web (such as persons).

The following lines represent the graph in Figure 2 in RDF/XML:

```{=html}
<table width="100%" border="1" cellspacing="0" cellpadding="0">
```
```{=html}
<tr>
```
```{=html}
<td style="vertical-align:top;text-align:right;">
```
`1`\
` 2`\
`3`\
`4`\
` 5`\
`6`\
`7`\
` 8`\
`9`\
`10`\
` 11`\
`12`\
`13`\
` 14`

```{=html}
</td>
```
```{=html}
<td>
```
``` XML
 <?xml version="1.0"?><br>
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
          xmlns:dc="http://purl.org/dc/elements/1.1/"
          xmlns:property="http://www.example.org/properties/"> <br>
     <rdf:Description rdf:about="http://www.example.org/index.html">
         <property:author>Pete Maravich</property:author>
     </rdf:Description> <br>
     <rdf:Description rdf:about="http://www.example.org/index.html">
         <dc:language>en</dc:language>
     </rdf:Description> <br>
     <rdf:Description rdf:about="http://www.example.org/index.html">
         <dc:title>Example_Title</dc:title>
     </rdf:Description> <br>
 </rdf:RDF>
```

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
</table>
```
`<small>`{=html}**Figure 3 - example_rdf.rdf**`</small>`{=html}

Let\'s examine the lines of code to get a better understanding of the
syntax:

-   {1} XML declaration, identifies the document as XML in the current
    version 1.0
-   {2} Start of an rdf:RDF element, identifies the following code as
    RDF - also declares an XML namespace *rdf*, all tags starting with
    the prefix rdf: are part of the namespace identified by the URIref
    *http://www.w3.org/1999/02/22-rdf-syntax-ns#* which describe the RDF
    vocabulary
-   {3} declares an XML namespace *dc*, all tags starting with the
    prefix dc: are part of the namespace identified by the URIref
    *http://purl.org/dc/elements/1.1/* - the *link* defines a standard
    vocabulary of terms for metadata
-   {4} declares an XML namespace *property*, all tags starting with the
    prefix property: are part of the namespace identified by the URIref
    *http://www.example.org/properties/* - this URI is fictitious and
    was chosen to indicate that one can create their own vocaburaly to
    describe resources
-   {5 to 7} represents a specific statement about the resource
    *http://www.example.org/index.html* as seen in the examples - Line 5
    declares the subject of the description - Line 6 provides a property
    element, the qualified name *property* is an abbreviation that
    represents the assigned namespace (line 4), property:author stands
    for *http://www.example.org/properties/author* - embedded in the
    property tag is the value(object) of the description as a plain
    literal

```{=html}
<!-- -->
```
-   {8 to 10} shows another statement - Line 8 again provides the
    subject - dc:language specifies the predicate for the statement,
    *http://purl.org/dc/elements/1.1/language* - the literal \'en\' is
    an international standard two-letter code for English

```{=html}
<!-- -->
```
-   {11 to 13} shows yet another statement - Line 10 to identify the
    subject - dc:title specifies the predicate for the statement,
    *http://purl.org/dc/elements/1.1/title* - the value Example_Title is
    the object
-   {14} ends the rdf:RDF element

Section 3 has covererd the basic structure of RDF and is intended to
provide a fundamental understanding of the topic. The next section will
cover some advanced structures and features of RDF.

## Advanced Concepts

**Structured Property Values and Blank Nodes**

As mentioned earlier the object of a statement can be a literal, a blank
node or a URI reference. The latter two give RDF more power because they
allow to create complex structures, so called **structured property
values**. For instance you consider describing the address of somebody.
An address is a structure that consists of different values such as a
street, a city, a state and a zipcode. In RDF one would identify the
adress as a resource to allow a more detailed description.

!structured RDF graph
`<small>`{=html}**Figure 4 - structured RDF graph**`</small>`{=html}

As you can see the value of the property *creator* is represented by a
reference using the URI *http://www.example.org/members/1234*. RDF
statements (additional arcs and nodes) can then be written with that
node as the subject, to represent the additional information like the
name of the creator and his address. The property *adress* itself is
represented by a URI, which allows a detailed description that is
aggregated from further statements about the address.

However the URIref *http://www.example.org/address/1234* may never need
to be referred to directly from outside a particular graph, and
therefore may not require a specific identifier. The concept above could
also be represented by using a **blank node** for the address object.
Blank nodes were called anonymous resources, they have no URIrefs and no
literals.

!structured RDF graph with a blank
node

`<small>`{=html}**Figure 5 - structured RDF graph using a blank
node**`</small>`{=html}

In RDF/XML the concept of structured property values and blank nodes are
represented like this:

```{=html}
<table width="100%" border="1" cellspacing="0" cellpadding="0">
```
```{=html}
<tr>
```
```{=html}
<td style="vertical-align:top;text-align:right;">
```
`1`\
` 2`\
`3`\
`4`\
` 5`\
`6`\
`7`\
`8`\
`9`\
`10`\
`11`\
`12`\
` 13`\
`14`\
`15`\
`16`\
`17`\
` 18`

```{=html}
</td>
```
```{=html}
<td>
```
``` XML
 <?xml version="1.0"?><br>
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
          xmlns:dc="http://purl.org/dc/elements/1.1/"
          xmlns:property="http://www.example.org/properties/"> <br>
     <rdf:Description rdf:about="http://www.example.org/index.html">
         <dc:creator>
             <rdf:Description rdf:about="http://www.example.org/members/1234">
                 <properties:name>Pete Maravich</properties:name>
                 <properties:address rdf:nodeID="abc"/>
             </rdf:Description>
         </dc:creator>
     </rdf:Description><br>
     <rdf:Description rdf:nodeID="abc">
         <properties:street>346 Broad Street</properties:street>
         <properties:city>Athens</properties:city>
         <properties:state>Georgia</properties:state>
     </rdf:Description> <br>
 </rdf:RDF>
```

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
</table>
```
`<small>`{=html}**Figure 6 - structured_rdf.xml**`</small>`{=html}

Let\'s examine the lines of code that represent the new concepts:

-   {5 to 12} describes the resource *http://www.example.org/index.html*
    that has the value *http://www.example.org/members/1234*
-   {7 to 10} displays a way to abbreviate multiple property elements
    for a resource - usually a node has multiple arcs(properties) coming
    off and instead of writing one description for each property one can
    abbreviate this by using multiple child property elements inside the
    node element describing the subject node
-   {9} shows how one can identify a blank node in RDF/XML - it is
    sometimes necessary that the same blank node in a graph is referred
    to in the RDF/XML in multiple places - if so, a blank node
    identifier can be given to the blank node for identifying it in the
    document
-   {13-17} displays the properties and values for the blank node
    identified in line {9}

## RDF applications

### Dublin Core Metadata Initiative

*The Dublin Core Metadata Initiative (DCMI) is
an organization dedicated to promoting the widespread adoption of
interoperable metadata standards and developing specialized metadata
vocabularies for describing resources that enable more intelligent
information discovery systems.*\
Basically the Dublin Core is a set of elements that are used to describe
a document. The goal of the Dublin Core is to provide a minimal set of
descriptive elements that support and simplify the description and the
automated indexing of document-like networked objects. Discovery tools
on the Internet, such as the \"Webcrawlers\" employed by popular World
Wide Web search engines use the metadata set. In addition, the Dublin
Core is meant to be sufficiently simple to be understood and used by the
wide range of authors and casual publishers who contribute information
to the Internet. (also see
RFC-2413)

Dublin Core Metadata Element
Set shows a description of all
current elements defined in the Dublin Core. In the following example
one can see an RDF document that uses the Dublin Core elements to
describe an article in a magazine:

```{=html}
<table width="100%" border="1" cellspacing="0" cellpadding="0">
```
```{=html}
<tr>
```
```{=html}
<td style="vertical-align:top;text-align:right;">
```
`1`\
` 2`\
`3`\
`4`\
` 5`\
`6`\
`7`\
`8`\
`9`\
`10`\
`11`\
`12`\
`13`\
`14`\
` 15`\
`16`\
`17`\
`18`\
`19`\
`20`\
` 21`

```{=html}
</td>
```
```{=html}
<td>
```
``` XML
 <?xml version="1.0"?><br>
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
          xmlns:dc="http://purl.org/dc/elements/1.1/"
          xmlns:dcterms="http://purl.org/dc/terms/"><br>
     <rdf:Description rdf:about="http://www.cio.com/archive/101504/km.html">
         <dc:title>Less for Success</dc:title>
         <dc:creator>Alice Dragoon</dc:creator>
         <dc:subject>
             <rdf:Bag>
                 <rdf:li>knowledge management</rdf:li>
                 <rdf:li>technology investments</rdf:li>
             </rdf:Bag>
         </dc:subject>
         <dc:description>Forget the big bang approach. When it comes to demonstrating the value
          of knowledge management, a piecemeal strategy works best.</dc:description>
         <dc:publisher>CXO Media</dc:publisher>
         <dcterms:issued>October 15, 2004</dcterms:issued>
         <dc:format>text/html</dc:format>
         <dc:language>en</dc:language>
         <dcterms:isPartOf rdf:resource="http://www.cio.com/archive/101504/index.html"/>
     </rdf:Description><br>
 </rdf:RDF>
```

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
</table>
```
`<small>`{=html}**Figure 7 - cio_article.rdf**`</small>`{=html}

### Adobe\'s XMP

The Extensible Metadata Platform is a specification describing RDF-based
data and storage models for metadata about documents in any format. XMP
can be included in text files such as HTML or SVG, image formats such as
JPEG or GIF and Adobe\'s own formats like Photoshop or Acrobat. Adobe is
making efforts that all of their applications will support XMP. However
Adobe claims that *XMP provides a standard format for the creation,
processing and interchange of metadata*, the specification is not a
standard.

**XMP provides the following:**

-   A data model - as a useful and flexible way of describing metadata
    in documents.
-   A storage model - for the implementation of the data model. This
    includes the serialization of the metadata as a stream of XML and
    XMP Packets, a means of packaging the data in files.
-   Schemas - predefined sets of metadata property definitions that are
    relevant for a wide range of applications, including all of Adobe's
    editing and publishing products, as well as for applications from a
    wide variety of vendors. XMP also provides guidelines for the
    extension and addition of schemas.

However XMP metadata vocubularly is relatively small,i.e. the ways to
describe a document are limited. To overcome this issue Adobe is using
metadata standards such as the Dublin Core and also allows users to
define their own metadata vocaburlarly.

\
The following screenshot is from Acrobat Professional 6.0 *Document
Metadata* feature. The description field allows users to define
metadata, whereas the advanced tab shows an overview of the metadata.
Under view *Source* one can see the metadata in RDF/XML.

!Abobe XMP
example{width="500"}\
`<small>`{=html}**Figure 8 - Adobe XMP example**`</small>`{=html}

The RDF/XML based representation of the document\'s metadata can be
found here. The
property funFactor expresses the hilariousness of a document. It was
included using the \'load\' functionality of Acrobat Professional to
test the addition of arbitrary metadata to the properties Acrobat
Professional already knew about.

### RSS - RDF Site Summary

RDF Site Summary (RSS) is also an application of RDF. Please have a look
at the Chapter on  RSS in this Wikibook.

## Creating an RDF Vocabulary

As seen earlier in the chapter one can create its own RDF metadata
vocabulary, despite using standards like the Dublin Core. This section
is intended to show a very general approach in creating such a personal
vocabulary. For a detailed description please see *Practical RDF -
Powers 2003*.

The first step in creating a vocabulary is to define the domain elements
and their properties within the given area interest. This means one has
to outline what kind of information about the resource should be
described. Let\'s say we want to save the following facts about a
resource:

```{=html}
<table width="50%" border="1" cellspacing="0" cellpadding="0">
```
```{=html}
<tr>
```
```{=html}
<td>
```
**Property**

```{=html}
</td>
```
```{=html}
<td>
```
**Description**

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
Title

```{=html}
</td>
```
```{=html}
<td>
```
Title of the resource

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
Created

```{=html}
</td>
```
```{=html}
<td>
```
Date of creation

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
Author

```{=html}
</td>
```
```{=html}
<td>
```
Author of the resource

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
Status

```{=html}
</td>
```
```{=html}
<td>
```
Current status of the resource

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
Subject

```{=html}
</td>
```
```{=html}
<td>
```
Subject/topic of the resource

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
Format

```{=html}
</td>
```
```{=html}
<td>
```
Format of the resource

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
FunFactor

```{=html}
</td>
```
```{=html}
<td>
```
FunFactor of the resource

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
</table>
```
\
The next step is to create a RDF Schema(RDFS) document for the new
vocabulary:

Here you can
see the definition for our desired properties. Using this RDFS one can
describe the article seen above the following way:\

```{=html}
<table width="100%" border="1" cellspacing="0" cellpadding="0">
```
```{=html}
<tr>
```
```{=html}
<td style="vertical-align:top;text-align:right;">
```
`1`\
` 2`\
`3`\
` 4`\
`5`\
`6`\
`7`\
`8`\
`9`\
`10`\
`11`\
`12`\
`13`\
`14`\
`15`\
`16`\
`17`\
` 18`

```{=html}
</td>
```
```{=html}
<td>
```
``` XML
 <?xml version="1.0"?><br>
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
          xmlns:same="http://mitglied.lycos.de/virtuoso5/elements/1.0/myschema#"><br>
     <rdf:Description rdf:about="http://www.cio.com/archive/101504/km.html">
         <same:title>Less for Success</same:title>
         <same:author>Alice Dragoon</same:author>
         <same:subject>
             <rdf:Bag>
                 <rdf:li>knowledge management</rdf:li>
                 <rdf:li>technology investments</rdf:li>
            </rdf:Bag>
         </same:subject>
         <same:format>text/html</same:format>
         <same:status>active</same:status>
         <same:created>2004-10-19</same:created>
         <same:funFactor>3</same:funFactor>
     </rdf:Description><br>
 </rdf:RDF>
```

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
</table>
```
`<small>`{=html}**Figure 9 - cio_article2.rdf**`</small>`{=html}

To validate its RDFS and RDF files one can use the W3C RDF
Validator.

## Exercises

1.  Create an RDF/XML document that describes an article of your choice
    (e.g. from magazines like CIO.com or ZDNet.com). Use the Dublin Core
    element set and the Dublin
    Core termsas a framework for your
    description. After completing the document please validate your work
    with the\
    W3C RDF Validator.

## References

-   RDF Primer - *W3C Recommendation 10 February 2004*,
    <http://www.w3.org/TR/rdf-primer/>
-   Shelley Powers - *Practical RDF*, O\'Reilly 2003
-   Tim Berners-Lee *Why RDF model is different from the XML model*,
    September 1998, <http://www.w3.org/DesignIssues/RDF-XML.html>
-   Dublin Core Metadata Initiative - <http://dublincore.org/>
-   Adobe XMP - <http://www.adobe.com/products/xmp/main.html>
-   XML.com - *XMP Lowdown*,
    <http://www.xml.com/pub/a/2004/09/22/xmp.html>


# XML - Managing Data Exchange/RSS

![](Feed-icon.svg "Feed-icon.svg")

## Learning Objectives

Upon completion of this chapter, you will

-   Understand the basics of RSS
-   Understand the history of RSS
-   Be able to construct a RSS 2.0 document using XML
-   Subscribe to an RSS aggregator/reader

## Introduction

RSS is a simple XML format used to syndicate headlines. It is now
popularly used by websites that publish new content regularly and
provide a list of headlines with links to their latest content. Content
such as news feeds, events listings, project updates, blogger and most
recently podcasting, video and image distribution can all be distributed
by RSS. RSS feeds are also used by major Internet portals such as
Google, Yahoo and AOL for people to personalize and have information
that they care about delivered to them, i.e. MyYahoo.

### What does RSS mean?

RSS is considered a name variously used to refer to three different
standards. The three separate branches are the RSS 0.9 branch, the RSS
1.0 branch (which is based on RDF) and RSS 2.0, and the initials have
been expanded into three different names: \"Really Simple Syndication\"
(RSS 0.9, 2.0), \"Rich Site Summary\" and \"RDF Site Summary\" (for RSS
1.0).

Several different versions have been developed by different developers
under different names. According to XML.com, seven versions of RSS have
been developed (see What is
RSS?). Because
RSS is understood as a term referring to many types of syndication
protocols, these various RSS protocols have sometimes been accused of
being \"incompatible\" with each other (see The myth of RSS
compatibility).
This is an important issue for RSS reader/aggregator developers.\

### History

The original version (version 0.90) of RSS was released by Netscape in
1999. Netscape developers were designing a format for making portals of
headlines for news sites. After Netscape released the simplified version
of RSS, they lost interest in developing RSS. However, another company,
UserLand Software took over with intention to use RSS with their
web-logging products and web-based writing software. While UserLand
Software continued development with version 0.91, a third non-commercial
group split off from the company and designed a new format based on
version 0.90, which was a non-simplified version. The new format
developed by this non-commercial group became known as version 1.0. In
the meantime UserLand Software grew angered at the new 1.0 version, kept
developing RSS and released version 2.0. Version 2.0 has become the
leader and most widely adopted version of RSS. The 2.0 specification was
donated to a non-commercial third party, Harvard Law School. Harvard Law
is now responsible for the future development of the RSS 2.0
specification. Below is a table that describes each version, the owner,
pros and cons, as well as its current status and recommendation for use.

```{=html}
<table border="1" summary="RSS versions and recommendations of use">
```
```{=html}
<caption>
```
RSS versions and recommendations, Table source: What is
RSS? XML.com

```{=html}
</caption>
```
```{=html}
<tr>
```
```{=html}
<th>
```
Version

```{=html}
</th>
```
```{=html}
<th>
```
Owner

```{=html}
</th>
```
```{=html}
<th>
```
Pros

```{=html}
</th>
```
```{=html}
<th>
```
Status

```{=html}
</th>
```
```{=html}
<th>
```
Recommendation

```{=html}
</th>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<th>
```
0.90

```{=html}
</th>
```
```{=html}
<td>
```
Netscape

```{=html}
</td>
```
```{=html}
<td>
```

```{=html}
</td>
```
```{=html}
<td>
```
Obsoleted by 1.0

```{=html}
</td>
```
```{=html}
<td>
```
Don\'t use

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<th>
```
0.91

```{=html}
</th>
```
```{=html}
<td>
```
UserLand

```{=html}
</td>
```
```{=html}
<td>
```
Drop dead simple

```{=html}
</td>
```
```{=html}
<td>
```
Officially obsoleted by 2.0, but still quite popular

```{=html}
</td>
```
```{=html}
<td>
```
Use for basic syndication. Easy migration path to 2.0 if you need more
flexibility

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<th>
```
0.92, 0.93, 0.94

```{=html}
</th>
```
```{=html}
<td>
```
UserLand

```{=html}
</td>
```
```{=html}
<td>
```
Allows richer metadata than 0.91

```{=html}
</td>
```
```{=html}
<td>
```
Obsoleted by 2.0

```{=html}
</td>
```
```{=html}
<td>
```
Use 2.0 instead

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<th>
```
1.0

```{=html}
</th>
```
```{=html}
<td>
```
RSS-DEV Working Group

```{=html}
</td>
```
```{=html}
<td>
```
RDF-based, extensibility via modules, not controlled by a single vendor

```{=html}
</td>
```
```{=html}
<td>
```
Stable core, active module development

```{=html}
</td>
```
```{=html}
<td>
```
Use for RDF-based applications or if you need advanced RDF-specific
modules

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<th>
```
2.0

```{=html}
</th>
```
```{=html}
<td>
```
UserLand

```{=html}
</td>
```
```{=html}
<td>
```
Extensibility via modules, easy migration path from 0.9x branch

```{=html}
</td>
```
```{=html}
<td>
```
Stable core, active module development

```{=html}
</td>
```
```{=html}
<td>
```
Use for general-purpose, metadata-rich syndication

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
</table>
```
## RSS structure

A RSS document is often known as RSS feed and can have three different
types of file extensions: .RSS, .XML and .RDF. All RSS documents must
conform 100% to the XML specification begin with the XML declaration. To
identify a RSS document, the top level starts with a
`<span style="color:Red;">`{=html}`<rss>`{=html}`</span>`{=html}
element, followed by a mandatory version attribute that specifies the
RSS version. Sub-element to the
`<span style="color:Red;">`{=html}`<rss>`{=html}`</span>`{=html}
element, is the single
`<span style="color:Red;">`{=html}`<channel>`{=html}`</span>`{=html}
element which contains a brief description of the channel. Below is a
sample of RSS(2.0) from the New York Times.\
**Exhibit 1: Data model for RSS**

``` XML
<rss version="2.0">
    <channel>
        <title>NYT > Home Page</title>
        <link> <nowiki>http    //www.nytimes.com/index.html</nowiki> </link>
        <description>New York Times > Breaking News, World News Multimedia</description>
        <copyright>Copyright 2004 The New York Times Company</copyright>
        <language>en-us</language>
        <lastBuildDate>Sun,  7 Nov 2004 13    30    01 EST</lastBuildDate>
        <image>
            <url> <nowiki>http    //www.nytimes.com/images/section/NytSectionHeader.gif</nowiki> </url>
            <title>NYT > Home Page</title>
            <link> <nowiki>http    //www.nytimes.com/index.html</nowiki> </link>
        </image>
        <item>
            <title>Iraq Declares State of Emergency as Insurgents Step Up Attacks</title>
            <link> <nowiki>http    //www.nytimes.com/2004/11/07/international/middleeast/07cnd-iraq.html</nowiki> </link>
            <description> Today's attacks, including three police post raids that killed 21, came a day after insurgents killed at least 30. </description>
            <author> By EDWARD WONG </author>
            <pubDate> Sun, 07 Nov 2004 00    00    00 EDT </pubDate>
            <guid> <nowiki>http    //www.nytimes.com/2004/11/07/international/middleeast/07cnd-iraq.html</nowiki> </guid>
        </item>
    </channel>
</rss>
```

`<small>`{=html}**Figure 1-1: New York Times -
HomePage.xml -
RSS version 2** `</small>`{=html}\
\
The `<span style="color:Red;">`{=html}`<channel>`{=html}`</span>`{=html}
element has three mandatory elements and several optional elements.\
**Mandatory `<channel>`{=html} elements:**

```{=html}
<table width="100%" border="1" cellspacing="0" cellpadding="0">
```
```{=html}
<tr>
```
```{=html}
<td>
```
Element

```{=html}
</td>
```
```{=html}
<td>
```
Description

```{=html}
</td>
```
```{=html}
<td>
```
Example

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
```{=html}
<title>
```
```{=html}
</td>
```
```{=html}
<td>
```
Name of the channel

```{=html}
</td>
```
```{=html}
<td>
```
\"The New York Times\"

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
`<description>`{=html}

```{=html}
</td>
```
```{=html}
<td>
```
Brief description of the channel

```{=html}
</td>
```
```{=html}
<td>
```
New York Times \> Breaking News, World News Multimedia

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
`<link>`{=html}

```{=html}
</td>
```
```{=html}
<td>
```
URL to the channel associated website

```{=html}
</td>
```
```{=html}
<td>
```
http://www.nytimes.com/index.html

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
</table>
```
\
**Optional `<channel>`{=html} elements:**

```{=html}
<table width="100%" border="1" cellspacing="0" cellpadding="0">
```
```{=html}
<tr>
```
```{=html}
<td>
```
Element

```{=html}
</td>
```
```{=html}
<td>
```
Description

```{=html}
</td>
```
```{=html}
<td>
```
Example

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
`<language>`{=html}

```{=html}
</td>
```
```{=html}
<td>
```
Channel language

```{=html}
</td>
```
```{=html}
<td>
```
en-us

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
`<copyright>`{=html}

```{=html}
</td>
```
```{=html}
<td>
```
Copyright notice for content in the channel

```{=html}
</td>
```
```{=html}
<td>
```
Copyright 2004 The New York Times Company

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
`<lastBuildDate>`{=html}

```{=html}
</td>
```
```{=html}
<td>
```
The last time the content of the channel was updated/changed

```{=html}
</td>
```
```{=html}
<td>
```
Sun, 7 Nov 2004 13:30:01 EST

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
</table>
```
\
Other optional elements include: managingEditor, webMaster, pubDate,
category, generator, docs, cloud, ttl, image, rating, textInput,
skipHours, skipDates. The requirement or sub-elements of each element
please refer to the RSS specification.(see at Harvard
Law).
Below are example of image element.\
\
`<image>`{=html} elements:\

```{=html}
<table width="100%" border="1" cellspacing="0" cellpadding="0">
```
```{=html}
<tr>
```
```{=html}
<td>
```
Element

```{=html}
</td>
```
```{=html}
<td>
```
Description

```{=html}
</td>
```
```{=html}
<td>
```
Example

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
`<link>`{=html}

```{=html}
</td>
```
```{=html}
<td>
```
The URL to the item

```{=html}
</td>
```
```{=html}
<td>
```
http://www.nytimes.com/index.html

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
```{=html}
<title>
```
```{=html}
</td>
```
```{=html}
<td>
```
Picture title

```{=html}
</td>
```
```{=html}
<td>
```
NYT \> Home Page

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
`<url>`{=html}

```{=html}
</td>
```
```{=html}
<td>
```
The URL to the picture

```{=html}
</td>
```
```{=html}
<td>
```
http://www.nytimes.com/images/section/NytSectionHeader.gif

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
</table>
```
A channel may contain a number of `<item>`{=html}s. An item may
represent a \"story\" - much like a story in a newspaper or magazine; if
so, its description is a synopsis of the story. The link points to the
full story. An item may also be complete in itself, if so, the
description contains the text (entity-encoded HTML is allowed; see
examples), and the link and title may be omitted.\
Each RSS channel can contain up to 15 items. All elements of an item are
optional,however, an `<item>`{=html} element must contain at least one

```{=html}
<title>
```
or `<description>`{=html} element.\
\
`<item>`{=html} elements:\

```{=html}
<table width="100%" border="1" cellspacing="0" cellpadding="0">
```
```{=html}
<tr>
```
```{=html}
<td>
```
Element

```{=html}
</td>
```
```{=html}
<td>
```
Description

```{=html}
</td>
```
```{=html}
<td>
```
Example

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
```{=html}
<title>
```
```{=html}
</td>
```
```{=html}
<td>
```
Title of the item

```{=html}
</td>
```
```{=html}
<td>
```
Iraq Declares State of Emergency as Insurgents Step Up Attacks

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
`<link>`{=html}

```{=html}
</td>
```
```{=html}
<td>
```
The URL to the item

```{=html}
</td>
```
```{=html}
<td>
```
http://www.nytimes.com/2004/11/07/international/middleeast/07cnd-iraq.html

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
`<description>`{=html}

```{=html}
</td>
```
```{=html}
<td>
```
Brief description of the item

```{=html}
</td>
```
```{=html}
<td>
```
Today\'s attacks, including three police post raids that killed 21, came
a day after insurgents killed at least 30.

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
`<author>`{=html}

```{=html}
</td>
```
```{=html}
<td>
```
Author\'s name and/or author\'s email address

```{=html}
</td>
```
```{=html}
<td>
```
mail@nytimes.com (Edward Wong)

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
`<pubDate>`{=html}

```{=html}
</td>
```
```{=html}
<td>
```
Date/time the item was published

```{=html}
</td>
```
```{=html}
<td>
```
Sun, 07 Nov 2004 00:00:00 EDT

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
<tr>
```
```{=html}
<td>
```
`<guid>`{=html}

```{=html}
</td>
```
```{=html}
<td>
```
Is a string that uniquely identifies the item. Can be used by the
aggregator to determine if an item is new.

```{=html}
</td>
```
```{=html}
<td>
```
http://www.nytimes.com/2004/11/07/international/middleeast/07cnd-iraq.html

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
</table>
```
Others include:\
source, enclosure, category, and comments.(see at Harvard
Law).\
\
An item can either be a child or a sibling of a channel.

```{=html}
<table width="100%" border="1" cellspacing="0" cellpadding="0">
```
```{=html}
<tr>
```
```{=html}
<td>
```
*\"child\"*

:   `<span style="color:Red;">`{=html}`<channel>`{=html}`</span>`{=html}

    :   \...
    :   `<span style="color:Blue;">`{=html}`<item>`{=html}`</span>`{=html}

        :   \.....
    :   `<span style="color:Blue;">`{=html}`</item>`{=html}`</span>`{=html}
:   `<span style="color:Red;">`{=html}`</channel>`{=html}`</span>`{=html}

```{=html}
</td>
```
```{=html}
<td>
```
*\"sibling\"*

:   `<span style="color:Red;">`{=html}`<channel>`{=html}`</span>`{=html}

    :   \...
:   `<span style="color:Red;">`{=html}`</channel>`{=html}`</span>`{=html}
:   `<span style="color:Red;">`{=html}`<item>`{=html}`</span>`{=html}

    :   \.....
:   `<span style="color:Red;">`{=html}`</item>`{=html}`</span>`{=html}

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
</table>
```
More optional elements visit RSS 2.0
Specification

## How does it work?

RSS can be divided into two parts; the reader/ag and the feed. The
reader is the program that reads and presents the RSS feed in an
understandable format. The feed is the website with its RSS file. RSS
feeds are typically identified on webpages with an orange rectangle
icon, or an orange icon with the letters RSS written on it. To view the
XML code, you simply have to click on the icon.

### Creating an RSS feed

A website author can establish a RSS feed for itself in different ways;
either by doing it manually, by using software or by online services.
Most large websites use content management software to produce their RSS
feed. Every time a change is made on their website, the content
management software produce a RSS file of the changes with the new items
added and old items removed.

### Subscribing to an RSS feed

As a RSS subscriber you need a RSS aggregator. By feeding a RSS link,
the aggregator will search for information you subscribed and display
them. Say that you subscribe on the sport section in the New York Times;
each time the NY Times publish a new sport article the article's
headlines, description and the URL will be displayed on your computer.
Whenever you are online, the aggregator will search out and sort your
list of interests and display them.

### RSS Aggregators

RSS aggregator (aka RSS Reader) is an application that is used to
collect, update and display RSS feeds. Below is a list of some RSS
aggregators for different platforms that the aggregator will work
properly on.

-   FeedReader - Windows
-   Sharp
    Reader -
    Windows(.NET)
-   NetNewsWire - Macintosh
-   Straw - Linux
-   Bloglines - Server-based
-   NewsHutch - Server-Based

Some others include:

-   AmphetaDesk - Windows,
    Macintosh, Linux
-   FeedDemon - Windows
-   FeedReader - Windows
-   NewsGator - Windows(.NET)
-   RSS NewsWatcher - Windows
-   Radio Userland -
    Windows, Macintosh
-   SlashDock -
    Macintosh
-   PocketFeed -
    PocketPC

\

## Future of RSS

The future of RSS seems very promising as version 2.0 has become
extremely popular with the Internet industry and somewhat the standard
of the RSS versions. Yahoo recently released its new version of Yahoo
Maps and the API is based on georRSS version 2.0. This version of Yahoo
Maps allows users to edit the information on the maps, which makes the
Maps and Local Search products more effective. RSS version 2.0 is also
very popular with distributing podcasts to the subscriber base along
with distributing content Google's blogger product. Furthermore, RSS is
being utilized in an innovative way for search engine marketers to
submit time sensitive content to the engines. The Mozilla Firefox
browser already contains an internal RSS aggregator that allows users to
view RSS news and blog headlines in the bookmark toolbar or bookmark
menu. This is accomplished through the Mozilla Firefox feature named
"Live Bookmarks". RSS has quickly become a mainstream technology in a
relatively short period and has definitely become a major player in the
Internet space.

## Use RSS on Firefox

## Summary

  -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Now, RSS is commonly used in areas such as, websites and blogs, with version 2.0 being the most popular standard. RSS feeds are typically identified on webpages with an orange rectangle icon, or an orange icon with the letters RSS written on it. To view the XML code, you simply have to click on the icon.
  -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Exercises

## Answers

## References

Technology at Harvard Law - Internet technology hosted by Berkman
Center - RSS 2.0 Specification\
Dive-into-XML by Mark Pilgrim - What is
RSS?\
Mozilla Firefox - Live
Bookmarks\
Apple - PodCasting\
RSS INFO - RSS info\
USA Today - USA Today\


# XML - Managing Data Exchange/Namespace

## Learning Objectives

Upon completion of this chapter, you will:

-   be able to understand what XML Namespace is and its purpose
-   be able to recognize XML Namespace structure and what each part is
    doing
-   be able to think of organizations in which Namespace would be
    necessary

## What is Namespace?

An XML namespace is a collection of names that are identified by a
Uniform Resource Identifier (URI) reference, which are used in XML
documents as element types and attribute names. URIs were used simply
because they are a well-known system for creating unique identifiers.
Namespaces consist of several parts including local names, namespace
URIs, prefixes and declarations. The combination of a local name and a
namespace is called a universal name. You might find it easier to think
of a namespace as a **dictionary** that is a source of definitions for
items that you use within an XML document.

All schemas include the namespace
<http://www.w3.org/2001/XMLSchema-instance>. You can think of this as
the master dictionary to which all schemas must refer because it defines
the fundamental items of an XML schema. The namespace\'s address looks
like a URL, but in XML we use the broader term Uniform Resource
Identifier
(URI).

Because a document can refer to multiple namespace, we need a convenient
short form for referencing the namespace. One of the common forms used
is **xsd** as illustrated in the following.

`xmlns:xsd="``http://www.w3.org/2001/XMLSchema-instance``"`

The *xlmns* informs XML that you are referencing a name space, and the
*xsd* indicates this is the short form of the namespace.

For example, you might use the following line of code in an XML schema

`<xsd:element name="item" type="xsd:string">`{=html}

The previous line of code states that the definition of element name and
string are found in \"<http://www.w3.org/2001/XMLSchema-instance>\"

Namespace enables you to use elements described in multiple schemas
within your XML document, so the short form of a namespace\'s URI is
useful for identifying the namespace to which you are referring.

## History

Namespace in XML was a new W3C recommendation in January, 1999.
Namespace was created to be a pretty simple method to distinguish names
used in XML documents. The main purpose of Namespace is to provide
programmers a method for which to grab elements and attributes that they
want, leaving behind other tags that they do not need. These
programmer-friendly names will be unique across the Internet. The XML
namespaces recommendation does not define anything except a two-part
naming system for element types and attributes.

For additional information regarding the W3C recommendation, follow this
link: <http://www.w3.org/TR/REC-xml-names/>.

## When would you use Namespace?

It would mainly be used to avoid naming conflicts. If you don't have any
duplicate elements or attributes in the XML that you use, namespaces are
not necessary. It is however beneficial if you have duplicate elements
or attributes. It basically makes two part structures that make it
unique. Instead of just defining element A, for example, you have to
define element A with some other type of identifier. That is where the
URI comes into play. The URI in combination with the element or
attribute creates your namespace and it is then a universal name.

## Namespace Structure

XML namespaces differ from the \"namespaces\" conventionally used in
computing disciplines in that the XML version has internal structure and
is not, mathematically speaking, a set.

This is an example of 2 Namespace declarations:

`    ``<Organization
       xmlns:addr="http://www.example.com/addresses"
       xmlns="http://www.example.com/files">`{=html}` `

The first declaration associates the addr prefix with the
"www.example.com/addresses" URI. The second declaration defines
www.example.com/files as the default namespace. If there is not a prefix
defined for that element, a default namespace is applied. This default
namespace is applied to all elements without a prefix. Please note,
however, that default namespaces do not apply directly to attributes.

## How Does It Work?

When specifying a universal name in an XML document, you use an
abbreviation based on an optional prefix that\'s attached to the local
name. This abbreviation is called the qualified name or qname. To
declare an XML namespace, you use an attribute whose name has the form:

`xmlns:prefix`

These attributes are often called xmlns attributes and their value is
the name of the XML namespace being declared. This is a Uniform Resource
Identifier. The first form of the attribute (xmlns:prefix) declares a
prefix to be associated with the XML namespace. The second form (xmlns)
declares that the specified namespace is the default XML namespace.

## Namespace Best Practices

-   Try to limit the number of Namespaces to about 5 per document. More
    than five namespaces in a document gets unwieldy.
-   Make distinctions in XML namespaces only when there are truly
    distinctions between the things being named.
-   Try to stick to documents in namespace normal form wherever possible
    because they are simplest to read and to process.
-   Avoid overriding namespaces frequently because it can cause
    confusion in your documents.

## Example of Namespace Use

Let's say we are going to be pulling address values from two different
sources and address from one source pulls in a mailing address while
from the other source, it pulls in a computer IP address. We'll need to
create a Namespace so that we can distinguish the two addresses
elements.

Postal Address XML document

```{=html}
<address>
```
100 Elm St., Apt#1

```{=html}
</address>
```
IP Address XML document

```{=html}
<address>
```
172.13.5.7

```{=html}
</address>
```
How do we distinguish these Address elements in the case that they need
to be combined into the same document? We would assign each address name
to a namespace. Therefore, it becomes defined in two parts, the address
element and the XML namespace. Every time the element Address comes up,
it will have to look at two things instead of one for definition, but
this look up only has to be performed one time because the combination
is universally unique.

In this instance, we could create Namespaces for the address element:

``` xml
<Example Organization
xmlns: addr="http://www.example.com/postal_addresses"
xmlns="http://www.example.com/ip_addresses">
```

The first declaration associates the prefix \'addr\' with the URI,
\"www.example.com/postal_addresses and the second declaration sets
\"www.example.com/ip_addresses\" as the default namespace. So, where a
the prefix \'addr\' is used, it will pull the postal address and for
others, it will pull the IP address.

## Defining the location of an XML schema

Assume you have created a schema, example.xsd, that is located in the
same directory as your XML document, example.xml. In the XML document
you will indicate the location of the schema with the following code.

`<xmlns:xsi='``http://www.w3.org/2001/XMLSchema-instance``' xsi:noNamespaceSchemaLocation='example.xsd'>`

Of course, if example.xsd is stored somewhere other than the same
directory as example.xml, you specify the full path.

## Potential Problems with Namespace

-   Different XML technologies are going to process namespaces
    differently. Some will see namespace declarations as such and some
    will just see them as attributes.
-   Namespace is a compromise solution that doesn\'t meet the needs of
    all users.
-   XML namespaces seem simple on their face, but they can cause real
    confusion and increased complexity if they are not handled or
    managed correctly. To manage Namespaces correctly, you must
    understand thoroughly the meaning, rules, and implications of the
    various concepts that make up the XML namespaces mechanism and stick
    consistently to simple conventions.
-   As mentioned in Best Practices, using more than 5 namespaces can get
    unwieldy. So, how do large organizations tackle this design
    difficulty if there is a need for many namespaces? The basic source
    of this problem is that naming convention for most information
    architecture is fundamental, but with XML, it was patched together
    as an afterthought. Namespaces have been very difficult to
    incorporate smoothly.

fr:Programmation XML/Espace de
nom


# XML - Managing Data Exchange/Business Intelligence and XML

## Learning objectives

Upon completion of this chapter, for a single entity you will be able to

-   create a report specification entirely in XML for Cognos ReportNet
-   update a report specification in XML format.
-   identify four main sections in a report specification

## Introduction

Every report created in Cognos ReportNet has a specification that is
written in XML, so you can customize it using XML editor or create a
report specification entirely in XML.

## Report Specification Flow

After you save a report and open it again, the report specification is
pulled from the content store as you can see in Figure 28.1. When you
edit it, the changes remain local on the client machine until you save
it. When you save the report, the content store is updated.

Figure 28.1 Report Specification Flow

You can see a sample of web report in figure 28.2 and this report can be
generated from XML file;

Figure 28.2 Sample of a report

## XML in Report Specification Structure

A report specification consists of four main sections.

-   Report Section
    -   XML Tag:
        -   `<report>`{=html}
        -   `<modelConnection>`{=html}
-   Query Section
    -   XML Tag:
        -   `<querySet>`{=html}
-   Layout Section
    -   XML Tag:
        -   `<layoutList>`{=html}
-   Variable Section
    -   XML Tag:
        -   ```{=html}
            <variableList>
            ```

At minimum, a report specification must include the
`<report>`{=html}`</report>`{=html} tags, as well as authoring language
and schema information.

The specification header in Report Section includes information about:

-   authoring language, "en-us" indicates American English. You can use
    other language than English for the report
-   namespace : <http://developer.sample.com/schemas/report/1>
-   package name: GSR
-   model version : \@name=\'model\'

```{=html}
<table width="100%" border="1" cellspacing="0" cellpadding="0">
```
```{=html}
<TR>
```
```{=html}
<TD bgcolor="lightyellow">
```
`<report xml:lang="en-us" xmlns="http://developer.sample.com/schemas/report/1/">`{=html}

`   ``<modelConnection name="/content/package[@name='GSR']/model[@name='model']"/>`{=html}

```{=html}
</pre>
```
```{=html}
</TD>
```
```{=html}
</TR>
```
```{=html}
</table>
```
The query section includes information about:

-   Cube elements are indicated by the `<cube>`{=html}`</cube>`{=html}
    tags which can contain:
    -   facts (`<factList>`{=html}`</factList>`{=html}. Country, First
        Name and Last Name are the facts.
    -   dimensions (`<dimension>`{=html}`</dimension>`{=html})
        consisting of levels(`<level>`{=html}`</level>`{=html})
    -   filters (`<filter>`{=html}`</filters>`{=html} consiting of
        conditions(`<condition>`{=html}`</conditions>`{=html}). Country
        is the filter for this report, which is equal to Germany.
-   Tabular model is contained in the
    `<tabularModel>`{=html}`</tabularModel>`{=html} tags.
    -   Each tabular model contains data items
        (`<dataItem>`{=html}`</dataItem>`{=html}) consisting of fully
        qualified expressions
        (`<expression>`{=html}`</expression>`{=html})
-   The query section of a report is contained in the
    `<querySet>`{=html}`</querySet>`{=html}tags.
-   The query section can include multiple queries, each of which is
    contained in the `<BIQuery>`{=html}`</BIQuery>`{=html}tags.

Add pages to a report specification:

-   You can add many pages to a report. Each page is outlined between
    the `<pageSet>`{=html} `</pageSet>`{=html}tags.
    -   Each page can consist of :
        -   a body ( mandatory)
        -   a header
        -   a footer

Add layout objects to a report:

-   Once you have added one or more pages to the report layout, you can
    add a variety of layout objects, such as :
    -   Text items
    -   Blocks
    -   Lists
    -   Charts
    -   Crosstabs
    -   Tables

Specify styles for layout objects:

-   You can use Cascading Style Sheets (CSS) attributes to determine the
    look and feel of objects in the layout.
-   CSS values are specified between the
    ```{=html}
    <style>
    ```
    ```{=html}
    </style>
    ```
    tags.
-   CSS values can apply to things like font sizes, background colors,
    and so forth.

Add Variables to a Report:

-   You can specify variables between the
    ```{=html}
    <variableList>
    ```
    ```{=html}
    </variableList>
    ```
    tags of the report specification., and each of variable includes an
    expression between the `<expression>`{=html}`</expression>`{=html}
    tags.
-   We can use Variable 1 that contains a list of possible values,
    example value: fr for using French language;

```{=html}
<table width="100%" border="1" cellspacing="0" cellpadding="0">
```
```{=html}
<TR>
```
```{=html}
<TD bgcolor="lightyellow">
```
```{=html}
<variableList>
```
`        ``<variable name=”Variable1” type=”locale”>`{=html}\
`         ``<expression>`{=html}`ReportLocale()``</expression>`{=html}\
`          ``<variableValueList>`{=html}\
`           ``<variableValue value=”fr”/>`{=html}\
`          ``</varialeValueList>`{=html}\
`         ``</variable>`{=html}\
`        `

```{=html}
</variableList>
```
```{=html}
</pre>
```
```{=html}
</TD>
```
```{=html}
</TR>
```
```{=html}
</TABLE>
```
Below is the complete XML file for the report in Figure 28.3

```{=html}
<table width="100%" border="1" cellspacing="0" cellpadding="0">
```
```{=html}
<TR>
```
```{=html}
<TD bgcolor="lightyellow">
```
    <report xml:lang="en-us" xmlns="http://developer.sample.com/schemas/report/1/">
        <!--RS:1.1-->
        <modelConnection name="/content/package[@name='GSR']/model[@name='model']"/>
        <querySet xml:lang="en-us">
            <BIQuery name="Query1">
                <cube>
                    <factList>
                        <item refItem="Country" aggregate="none"/>
                        <item refItem="First name" aggregate="none"/>
                        <item refItem="Last name" aggregate="none"/>
                    </factList>
                </cube>
                <tabularModel>
                    <dataItem name="Country" aggregate="none">
                        <expression>[gsrs].[addr].[Country]</expression>
                    </dataItem>
                    <dataItem name="First name" aggregate="none">
                        <expression>[gsrs].[Person].[First name]</expression>
                    </dataItem>
                    <dataItem name="Last name" aggregate="none">
                        <expression>[gsrs].[Person].[Last name]</expression>
                    </dataItem>
                    <filter>
                        <condition>[gsrs].[addr].[Country]='Germany'</condition>
                    </filter>
                </tabularModel>
            </BIQuery>
        </querySet>
        <layoutList>
            <layout>
                <pageSet>
                    <page name="Page1">
                        <pageBody>
                            <list refQuery="Query1">
                                <listColumnTitles>
                                    <listColumnTitle>
                                        <textItem>
                                            <queryItemRef refItem="Country" content="label"/>
                                        </textItem>
                                    </listColumnTitle>
                                    <listColumnTitle>
                                        <textItem>
                                            <queryItemRef refItem="First name" content="label"/>
                                        </textItem>
                                    </listColumnTitle>
                                    <listColumnTitle>
                                        <textItem>
                                            <queryItemRef refItem="Last name" content="label"/>
                                        </textItem>
                                    </listColumnTitle>
                                </listColumnTitles>
                                <listColumns>
                                    <listColumn>
                                        <textItem>
                                            <queryItemRef refItem="Country"/>
                                        </textItem>
                                    </listColumn>
                                    <listColumn>
                                        <textItem>
                                            <queryItemRef refItem="First name"/>
                                        </textItem>
                                    </listColumn>
                                    <listColumn>
                                        <textItem>
                                            <queryItemRef refItem="Last name"/>
                                        </textItem>
                                    </listColumn>
                                </listColumns>
                                <style>
                                    <CSS value="border-collapse:collapse"/>
                                </style>
                                <XMLAttribute name="RS_ListGroupInfo" value=""/>
                            </list>
                        </pageBody>
                        <pageHeader>
                            <block class="reportTitle">
                                <textItem class="reportTitleText">
                                    <text/>
                                </textItem>
                            </block>
                            <style>
                                <CSS value="padding-bottom:10px"/>
                            </style>
                        </pageHeader>
                        <pageFooter>
                            <table>
                                <tableRow>
                                    <tableCell>
                                        <textItem>
                                            <expression>AsOfDate()</expression>
                                        </textItem>
                                        <style>
                                            <CSS value="vertical-align:top;text-align:left;width:25%"/>
                                        </style>
                                    </tableCell>
                                    <tableCell>
                                        <textItem>
                                            <text>- </text>
                                        </textItem>
                                        <textItem>
                                            <expression>PageNumber()</expression>
                                        </textItem>
                                        <textItem>
                                            <text> -</text>
                                        </textItem>
                                        <style>
                                            <CSS value="vertical-align:top;text-align:center;width:50%"/>
                                        </style>
                                    </tableCell>
                                    <tableCell>
                                        <textItem>
                                            <expression>AsOfTime()</expression>
                                        </textItem>
                                        <style>
                                            <CSS value="vertical-align:top;text-align:right;width:25%"/>
                                        </style>
                                    </tableCell>
                                </tableRow>
                                <style>
                                    <CSS value="border-collapse:collapse;width:100%"/>
                                </style>
                            </table>
                            <style>
                                <CSS value="padding-top:10px"/>
                            </style>
                        </pageFooter>
                    </page>
                </pageSet>
            </layout>
        </layoutList>
    </report>

```{=html}
</TD>
```
```{=html}
</TR>
```
```{=html}
</TABLE>
```
```{=html}
<table width="100%" border="1" bgcolor="lightgreen">
```
```{=html}
<tr>
```
```{=html}
<td>
```
`<b>`{=html} `<span style="color:SaddleBrown;">`{=html}Section summary:
As Report Specification sticks to XML Rules it is favored for creating
and updating a markup file`</span>`{=html} `</b>`{=html}

```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
</table>
```
```{=html}
</td>
```
```{=html}
</tr>
```
```{=html}
</table>
```
### Exercise

The end user wants to read the report in Japanese language, so you have
to add a variable for Japanese language.

### Answers


# XML - Managing Data Exchange/Handling XML with MySQL

**Author:** Shayla S. Lee 01:39, 15 November
2005 (UTC)

## Introduction

**MySQL** is an open source relational database that supports XML. You
can use the MySQL command line or a programming language of your choice
to convert your MySQL databases and or tables to a well formed XML
document.

### Supported Versions

XML is supported in MySQL version 3.23.48 and higher. A free version of
MySQL can be downloaded from MySQL.com.

### Using the MySQL Command Line

Use the \--xml or -X option with either the mysqldump or mysql command
to produce XML output.

**mysqldump Syntax:**

`mysqldump --xml -u username -p databasename [tablename] > filename.xml`

**mysql Syntax:**

`\T "filename.xml"`\
`mysql -X -u username -p databasename [tablename]`

**OR**

`\T "filename.xml"`\
`mysql -X -u username -p databasename tablename -e`\
`'select columnname, columnname`\
` from tablename'`

In the latter mysql syntax example, you can also specify a where
condition as well as restrict the where condition just as you would in a
regular sql select statement.

**Explanation of commands and options:**

**mysqldump** is a mysql output command.

**\\T** is a mysql output command.

**-e** is a mysql option that tells mysql to execute the following
select statement.

**\--xml** is the mysql option for producing XML output.

**-u** is a mysql option which tells mysql that the next command line
item is your username.

**username** is your mysql username. It will be used to authenticate you
to the mysql database.

**-p** is a mysqldump option that tells mysql that the next command line
item is your password. If do not want your password to be visible on the
command line, then do not supply your password after the -p option and
mysql will prompt you for it later.

**databasename** is the name of the database that you want to output to
xml.

**tablename** is the name of the table that you want to output to xml.
Supplying the tablename is optional.

The **\>** symbol is the output symbol that tells mysql to output the
results to the following filename.

**filename.xml** is the filename that you want to output the XML
results.


# XML - Managing Data Exchange/XML Encryption

**Author**: Shayla S. Lee 02:38, 15 November
2005 (UTC)

## Introduction

XML encryption was developed to address two common areas not addressed
by the Transport Layer Security and Secure Socket Layer protocol
(TLS/SSL). TLS/SSL is a very secure and reliable protocol that provides
end-to-end security sessions between two parties. XML adds an extra
layer of security to TLS/SSL by encrypting part or all of the data being
exchanged and by allowing for secure sessions between more than two
parties. In other words, each party can maintain secure or insecure
sessions with any of the communicating parties, and both secure and
non-secure data can be exchanged in the same document. Furthermore, XML
encryption can handle both XML and non-XML (e.g. binary) data.

## Encryption Syntax

All XML encrypted files must start with the following XML preamble,
declaration, internal entity, and import.

`Schema Definition:`\
` `

```{=html}
<?xml version="1.0" encoding="utf-8"?>
```
` <!DOCTYPE schema  PUBLIC "-//W3C//DTD XMLSchema 200102//EN"`\
`  "``http://www.w3.org/2001/XMLSchema.dtd``"`\
`  `\
`    <!ATTLIST schema`\
`      xmlns:xenc CDATA #FIXED '`[`http://www.w3.org/2001/04/xmlenc#``'`\
`      xmlns:ds CDATA #FIXED '``http://www.w3.org/2000/09/xmldsig#``'>`\
`    <!ENTITY xenc '``http://www.w3.org/2001/04/xmlenc#``'>`\
`    <!ENTITY % p ''>`\
`    <!ENTITY % s ''>`\
`   ]>`\
` `\
` ``<schema xmlns='http://www.w3.org/2001/XMLSchema' version='1.0'
          xmlns:ds='http://www.w3.org/2000/09/xmldsig#'
          xmlns:xenc='http://www.w3.org/2001/04/xmlenc#'
          targetNamespace='http://www.w3.org/2001/04/xmlenc#'
          elementFormDefault='qualified'>`{=html}\
`   ``<import namespace='http://www.w3.org/2000/09/xmldsig#'
            schemaLocation='http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-   schema.xsd'/>`{=html}

### EncryptedType Element

**EncryptedType** is the abstract type from which EncryptedData and
EncryptedKey are derived.

` Schema Definition:`\
`  ``<complexType name='EncryptedType' abstract='true'>`{=html}\
`   ``<sequence>`{=html}\
`     ``<element name='EncryptionMethod' type='xenc:EncryptionMethodType'
               minOccurs='0'/>`{=html}\
`     ``<element ref='ds:KeyInfo' minOccurs='0'/>`{=html}\
`     ``<element ref='xenc:CipherData'/>`{=html}\
`     ``<element ref='xenc:EncryptionProperties' minOccurs='0'/>`{=html}\
`   ``</sequence>`{=html}\
`   ``<attribute name='Id' type='ID' use='optional'/>`{=html}\
`   ``<attribute name='Type' type='anyURI' use='optional'/>`{=html}\
`   ``<attribute name='MimeType' type='string' use='optional'/>`{=html}\
`   ``<attribute name='Encoding' type='anyURI' use='optional'/>`{=html}` `\
`  ``</complexType>`{=html}

**Syntax Explanation**

**EncryptionMethod** is an optional element that describes the
encryption algorithm applied to the cipher data. If the element is
absent, the encryption algorithm must be known by the recipient or the
decryption will fail.

`<element name='EncryptionMethod' type='xenc:EncryptionMethodType'
               minOccurs='0'/>`{=html}

**ds:KeyInfo** is an optional element that carries information about the
key used to encrypt the data. Subsequent sections of this specification
define new elements that may appear as children of ds:KeyInfo.

`<element ref='ds:KeyInfo' minOccurs='0'/>`{=html}

**CipherData** is a mandatory element that contains the CipherValue or
CipherReference with the encrypted data.

`<element ref='xenc:CipherData'/>`{=html}

**EncryptionProperties** can contain additional information concerning
the generation of the EncryptedType (e.g., date/time stamp).

`<element ref='xenc:EncryptionProperties' minOccurs='0'/>`{=html}

**Id** is an optional attribute providing for the standard method of
assigning a string id to the element within the document context.

`<attribute name='Id' type='ID' use='optional'/>`{=html}

**Type** is an optional attribute identifying type information about the
plaintext form of the encrypted content. While optional, this
specification takes advantage of it for mandatory processing in
dycryption. If the EncryptedData element contains data of Type
\'element\' or element \'content\', and replaces that data in an XML
document context, it is strongly recommended the Type attribute be
provided. Without this information, the decryptor will be unable to
automatically restore the XML document to its original cleartext form.

`<attribute name='Type' type='anyURI' use='optional'/>`{=html}

**MimeType** is an optional (advisory) attribute which describes the
media type of the data which has been encrypted. The value of this
attribute is a string with values defined by \[MIME\]. For example, if
the data that is encrypted is a base64 encoded PNG, the transfer
Encoding may be specified as
\'<http://www.w3.org/2000/09/xmldsig#base64>\' and the MimeType as
\'image/png\'. This attribute is purely advisory; no validation of the
MimeType information is required and it does not indicate the encryption
application must do any additional processing. Note, this information
may not be necessary if it is already bound to the identifier in the
Type attribute. For example, the Element and Content types defined in
this specification are always UTF-8 encoded text.

`<attribute name='MimeType' type='string' use='optional'/>`{=html}

### EncryptionMethod Element

**EncryptionMethod** is an optional element that describes the
encryption algorithm applied to the cipher data. If the element is
absent, the encryption algorithm must be known by the recipient or the
decryption will fail. The permitted child elements of the
EncryptionMethod are determined by the specific value of the Algorithm
attribute URI.

`Schema Definition:`\
` ``<complexType name='EncryptionMethodType' mixed='true'>`{=html}\
`   ``<sequence>`{=html}\
`     ``<element name='KeySize' minOccurs='0' type='xenc:KeySizeType'/>`{=html}\
`     ``<element name='OAEPparams' minOccurs='0' type='base64Binary'/>`{=html}\
`     ``<any namespace='##other' minOccurs='0' maxOccurs='unbounded'/>`{=html}\
`   ``</sequence>`{=html}\
`   ``<attribute name='Algorithm' type='anyURI' use='required'/>`{=html}\
` ``</complexType>`{=html}

### CipherData Element

**CipherData** is a mandatory element that provides the encrypted data.
It must either contain the encrypted octet sequence as base64 encoded
text of the CipherValue element, or provide a reference to an external
location containing the encrypted octet sequence via the CipherReference
element.

`Schema Definition:`\
` ``<element name='CipherData' type='xenc:CipherDataType'/>`{=html}\
` ``<complexType name='CipherDataType'>`{=html}\
`    ``<choice>`{=html}\
`      ``<element name='CipherValue' type='base64Binary'/>`{=html}\
`      ``<element ref='xenc:CipherReference'/>`{=html}\
`    ``</choice>`{=html}\
`  ``</complexType>`{=html}

### CipherReference Element

**CipherReference** identifies a source which, when processed, yields
the encrypted octet sequence CipherReference is used when CipherValue is
not supplied directly. The actual value is obtained as follows. The
CipherReference URI contains an identifier that is dereferenced. Should
the CipherReference element contain an OPTIONAL sequence of Transforms,
the data resulting from dereferencing the URI is transformed as
specified so as to yield the intended cipher value. For example, if the
value is base64 encoded within an XML document; the transforms could
specify an XPath expression followed by a base64 decoding so as to
extract the octets.

`Schema Definition:`\
` ``<element name='CipherReference' type='xenc:CipherReferenceType'/>`{=html}\
`  ``<complexType name='CipherReferenceType'>`{=html}\
`      ``<sequence>`{=html}\
`        ``<element name='Transforms' type='xenc:TransformsType' minOccurs='0'/>`{=html}\
`      ``</sequence>`{=html}\
`      ``<attribute name='URI' type='anyURI' use='required'/>`{=html}\
`  ``</complexType>`{=html}

`   ``<complexType name='TransformsType'>`{=html}\
`      ``<sequence>`{=html}\
`        ``<element ref='ds:Transform' maxOccurs='unbounded'/>`{=html}` `\
`      ``</sequence>`{=html}\
`    ``</complexType>`{=html}

**Cipher Reference with Optional Tranform feature and Tranform
Algorithm:**

`<CipherReference URI="http://www.example.com/CipherValues.xml">`{=html}\
`   ``<Transforms>`{=html}\
`     ``<ds:Transform
       Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116">`{=html}\
`         ``<ds:XPath xmlns:rep="http://www.example.org/repository">`{=html}\
`           self::text()[parent::rep:CipherValue[@Id="example1"]]`\
`         ``</ds:XPath>`{=html}\
`     ``</ds:Transform>`{=html}\
`     ``<ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#base64"/>`{=html}\
`   ``</Transforms>`{=html}\
` ``</CipherReference>`{=html}

### EncryptedData Element

**EncryptedData** is the core element in the syntax. Not only does its
CipherData child contain the encrypted data, but it\'s also the element
that replaces the encrypted element, or serves as the new document root.

`Schema Definition:`\
` ``<element name='EncryptedData' type='xenc:EncryptedDataType'/>`{=html}\
` ``<complexType name='EncryptedDataType'>`{=html}\
`   ``<complexContent>`{=html}\
`    ``<extension base='xenc:EncryptedType'>`{=html}\
`    ``</extension>`{=html}\
`   ``</complexContent>`{=html}\
` ``</complexType>`{=html}

## Resources

The information above was obtained from W3C and IBM. For more
information, please visit the following links:

`http://www.w3.org/TR/2002/CR-xmlenc-core-20020802/#sec-Encryption-Syntax`\
`http://www-128.ibm.com/developerworks/xml/library/x-encrypt/`