XML

 


COIN78 - XML Lesson 7: XML Namespaces and XML



Section 1: Introduction to Namespaces in XSD

In this section you will look at xml and schema files that import namespaces from other files.

  1. Camera.xml creates name spaces for element definitions that it imports from Nikon, Olympus, and Pentax schemas. Elements referencing the schema documents are shown below.

    <?xml version="1.0"?>
    <camera xmlns="http://www.camera.org" 
            xmlns:nikon="http://www.nikon.com" 
            xmlns:olympus="http://www.olympus.com" 
            xmlns:pentax="http://www.pentax.com">
        <body>
            <nikon:description>
                Ergonomically designed casing for easy handling
            </nikon:description>
        </body>
        <lens>
            <olympus:zoom>300mm</olympus:zoom>
            <olympus:f-stop>1.2</olympus:f-stop>
        </lens>
        <manual_adapter>
            <pentax:speed>1/10,000 sec to 100 sec</pentax:speed>
        </manual_adapter>
    </camera>

  2. Camera_xsd.xml - is validated by Camera.xsd, including schema definitions imported from Nikon.xsd, Olympus.xsd, and Pentax.xsd.

    <?xml version="1.0"?>
    <camera xmlns="http://www.camera.org" 
            xmlns:nikon="http://www.nikon.com" 
            xmlns:olympus="http://www.olympus.com" 
            xmlns:pentax="http://www.pentax.com"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xsi:schemaLocation="http://www.camera.org Camera.xsd 
                  http://www.nikon.com Nikon.xsd 
                  http://www.olympus.com Olympus.xsd http://www.pentax.com Pentax.xsd">
        <body>
            <nikon:description>
                Ergonomically designed casing for easy handling
            </nikon:description>
        </body>
        <lens>
            <olympus:zoom>300mm</olympus:zoom>
            <olympus:f-stop>1.2</olympus:f-stop>
        </lens>
        <manual_adapter>
            <pentax:speed>1/10,000 sec to 100 sec</pentax:speed>
        </manual_adapter>
    </camera>

  3. Camera.xsd shows the references to Nikon, Olympus, and Pentax elements.

    <?xml version="1.0"?>
    <xsd:schema targetNamespace="http://www.camera.org" 
                xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                xmlns:pentax="http://www.pentax.com" 
                xmlns:olympus="http://www.olympus.com" 
                xmlns:nikon="http://www.nikon.com" 
                xmlns="http://www.camera.org" 
                elementFormDefault="qualified">
        <xsd:import namespace="http://www.nikon.com" schemaLocation="Nikon.xsd"/>
        <xsd:import namespace="http://www.olympus.com" schemaLocation="Olympus.xsd"/>
        <xsd:import namespace="http://www.pentax.com" schemaLocation="Pentax.xsd"/>
        <xsd:element name="camera">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element name="body" type="nikon:body_type"/>
                    <xsd:element name="lens" type="olympus:lens_type"/>
                    <xsd:element name="manual_adapter" type="pentax:manual_adapter_type"/>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
    </xsd:schema>

  4. Nikon.xsd shows the references to Nikon elements.

    <?xml version="1.0"?>
    <xsd:schema targetNamespace="http://www.nikon.com" 
                xmlns="http://www.nikon.com" 
                xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                elementFormDefault="qualified">
        <xsd:complexType name="body_type">
            <xsd:sequence>
                <xsd:element name="description" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:schema>

  5. Olympus.xsd shows the references to Olympus elements.

    <?xml version="1.0"?>
    <xsd:schema targetNamespace="http://www.olympus.com" 
                xmlns="http://www.olympus.com" 
                xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                elementFormDefault="qualified">
        <xsd:complexType name="lens_type">
            <xsd:sequence>
                <xsd:element name="zoom" type="xsd:string"/>
                <xsd:element name="f-stop" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:schema>

  6. Pentax.xsd shows the references to Pentax elements.

    <?xml version="1.0"?>
    <xsd:schema targetNamespace="http://www.pentax.com" 
                xmlns="http://www.pentax.com" 
                xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                elementFormDefault="qualified">
        <xsd:complexType name="manual_adapter_type">
            <xsd:sequence>
                <xsd:element name="speed" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:schema>

  7. The entire archive zipped for you to download an examine - Camera.zip

Section 2

In this section, there are four example files that have prefixed elements using custom namespaces. Use these examples for creating names spaces for your own schema. Right click on the link to download the file for local view. Thanks to Michael Mennis for creating and contributing these files.

  1. An address book with custom namespaces - address_book_ns.xml

    <?xml version="1.0" encoding="UTF-8"?>
    
    <!-- This document is the pattern that will import namespaces for validation -->
    <address_book xmlns="http://www.addressbook.org" 
                  xmlns:name="http://www.name.org" 
                  xmlns:address="http://www.address.org" 
                  xmlns:contact="http://www.contact.org" 
                  xmlns:comments="http://www.comments.org">
        <record>
            <name>
                <name:first_name>first name</name:first_name>
                <name:middle_name>middle name</name:middle_name>
                <name:last_name>last name</name:last_name>
                <name:nick_name>nick name</name:nick_name>
            </name>
            <address>
                <address:street>street</address:street>
                <address:street_detail>street detail</address:street_detail>
                <address:city>city</address:city>
                <address:state>state</address:state>
                <address:zipcode>90000-0000</address:zipcode>
            </address>
            <contact>
                <contact:home_phone>888-555-1212</contact:home_phone>
                <contact:work_phone>888-555-1212</contact:work_phone>
                <contact:cell_phone>888-555-1212</contact:cell_phone>
                <contact:fax_number>888-555-1212</contact:fax_number>
                <contact:email>user@provider.com</contact:email>
            </contact>
            <comments>
                <comments:comment>comments</comments:comment>
            </comments>
        </record>
    </address_book>

  2. The file above linked to a validating schema - address_book_ns_xsd.xml

    <?xml version="1.0" encoding="UTF-8"?>
    
    <!-- This document will import namespaces for validation -->
    <address_book xmlns="http://www.addressbook.org" 
                  xmlns:name="http://www.name.org" 
                  xmlns:address="http://www.address.org" 
                  xmlns:contact="http://www.contact.org" 
                  xmlns:comments="http://www.comments.org" 
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                  xsi:schemaLocation="http://www.addressbook.org 
                      AddressBook.xsd http://www.address.org 
                      Address.xsd http://www.name.org 
                      Name.xsd http://www.contact.org 
                      Contact.xsd http://www.comments.org/ 
                      Comments.xsd">
        .
        .
        .
    </address_book>

  3. The schema for the address book with custom namespaces - AddressBook.xsd

    <?xml version="1.0"?>
    <xsd:schema targetNamespace="http://www.addressbook.org" 
                xmlns:comments="http://www.comments.org" 
                xmlns:contact="http://www.contact.org" 
                xmlns:address="http://www.address.org" 
                xmlns:name="http://www.name.org" 
                xmlns="http://www.addressbook.org" 
                xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                elementFormDefault="qualified">
        <xsd:import namespace="http://www.name.org" schemaLocation="Name.xsd"/>
        <xsd:import namespace="http://www.address.org" schemaLocation="Address.xsd"/>
        <xsd:import namespace="http://www.contact.org" schemaLocation="Contact.xsd"/>
        <xsd:import namespace="http://www.comments.org" schemaLocation="Comments.xsd"/>
        <xsd:element name="address_book" type="address_bookType"/>
        <xsd:complexType name="address_bookType">
            <xsd:sequence>
                <xsd:element name="record" type="recordType" minOccurs="0" 
                             maxOccurs="unbounded"/>
            </xsd:sequence>
        </xsd:complexType>
        <xsd:complexType name="recordType">
            <xsd:sequence>
                <xsd:element name="name" type="name:nameType"/>
                <xsd:element name="address" type="address:addressType"/>
                <xsd:element name="contact" type="contact:contactType"/>
                <xsd:element name="comments" type="comments:commentType"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:schema>

  4. The schema for the name section - Name.xsd

    <?xml version="1.0"?>
    <xsd:schema targetNamespace="http://www.name.org" 
                xmlns="http://www.name.org" 
                xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                elementFormDefault="qualified">
        <xsd:complexType name="nameType">
            <xsd:sequence>
                <xsd:element name="first_name" type="xsd:string"/>
                <xsd:element name="middle_name" type="xsd:string"/>
                <xsd:element name="last_name" type="xsd:string"/>
                <xsd:element name="nick_name" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:schema>

  5. The schema for the address section - Address.xsd

    <?xml version="1.0"?>
    <xsd:schema targetNamespace="http://www.address.org" 
                xmlns="http://www.address.org" 
                xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                elementFormDefault="qualified">
        <xsd:complexType name="addressType">
            <xsd:sequence>
                <xsd:element name="street" type="xsd:string"/>
                <xsd:element name="street_detail" type="xsd:string"/>
                <xsd:element name="city" type="xsd:string"/>
                <xsd:element name="state" type="xsd:string"/>
                <xsd:element name="zipcode" type="zipcodeType"/>
            </xsd:sequence>
        </xsd:complexType>
        <xsd:simpleType name="zipcodeType">
            <xsd:restriction base="xsd:string">
                <xsd:pattern value="\d{5}(-\d{4})?"/>
            </xsd:restriction>
        </xsd:simpleType>
    </xsd:schema>

  6. The schema for the contact section - Contact.xsd

    <?xml version="1.0"?>
    <xsd:schema targetNamespace="http://www.contact.org"  
                xmlns="http://www.contact.org"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                elementFormDefault="qualified">
        <xsd:complexType name="contactType">
            <xsd:sequence>
                <xsd:element name="home_phone" type="phoneType"/>
                <xsd:element name="work_phone" type="phoneType"/>
                <xsd:element name="cell_phone" type="phoneType"/>
                <xsd:element name="fax_number" type="phoneType"/>
                <xsd:element name="email" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
        <xsd:simpleType name="phoneType">
            <xsd:restriction base="xsd:string">
                <xsd:pattern value="\d{3}\-\d{3}\-\d{4}"/>
            </xsd:restriction>
        </xsd:simpleType>
    </xsd:schema>

  7. The schema for the comments section - Comments.xsd

    <?xml version="1.0"?>
    <xsd:schema targetNamespace="http://www.comments.org"
                xmlns="http://www.comments.org" 
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
                elementFormDefault="qualified">
        <xsd:complexType name="commentType">
            <xsd:sequence>
                <xsd:element name="comment" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:schema>

  8. The entire archive zipped for you to download an examine - Address.zip

Section 3

In this section, an address book with slightly different prefixed elements and namespaces were created (thanks to Pushpa and Unice Chang) These can be viewed as separate files or as a complete archive in zipped format. This set may give you even more ideas.

  1. An address book with prefixed elements and custom namespaces - address_book_imported.xml

    <?xml version="1.0" standalone="no"?>
    <!--Declaration of qualified locals with default namespace-->
    <!-- Created by Pushpa - 05/13/2002 Modified by RDC and Unice Change 05/31/2003 -->
    
    <address_book>
        <record ID="1">
            <name>
                <nm:first_name>first name</nm:first_name>
                <nm:middle_name>middle name</nm:middle_name>
                <nm:last_name>last name</nm:last_name>
            </name>
            <address>
                <add:street_address>street address</add:street_address>
                <add:street_address_detail>street address detail</add:street_address_detail>
                <add:city>city</add:city>
                <add:state>state</add:state>
                <add:zipcode>94000</add:zipcode>
            </address>
            <contact>
                <con:home_phone>888-555-1212</con:home_phone>
                <con:work_phone>888-555-1212</con:work_phone>
                <con:cell_phone>888-555-1212</con:cell_phone>
                <con:email_address>user@whatever.com</con:email_address>
            </contact>
            <other_info>
                <inf:birth_date>888-555-1212</inf:birth_date>
                <inf:anniversary>888-555-1212</inf:anniversary>
                <inf:personal_website>http://www.whatver.com</inf:personal_website>
                </other_info>
            <comments>
                <com:text>Any comment about the person</com:text>
            </comments>
        </record>
        <record ID="2">
            <name>
                <nm:first_name>first name</nm:first_name>
                <nm:middle_name>middle name</nm:middle_name>
                <nm:last_name>last name</nm:last_name>
            </name>
            <address>
                <add:street_address>street address</add:street_address>
                <add:street_address_detail>street address detail</add:street_address_detail>
                <add:city>city</add:city>
                <add:state>state</add:state>
                <add:zipcode>94000</add:zipcode>
            </address>
            <contact>
                <con:home_phone>888-555-1212</con:home_phone>
                <con:work_phone>888-555-1212</con:work_phone>
                <con:cell_phone>888-555-1212</con:cell_phone>
                <con:email_address>user@whatever.com</con:email_address>
            </contact>
            <other_info>
                <inf:birth_date>888-555-1212</inf:birth_date>
                <inf:anniversary>888-555-1212</inf:anniversary>
                <inf:personal_website>http://www.whatver.com</inf:personal_website>
            </other_info>
            <comments>
                <com:text>Any comment about the person</com:text>
            </comments>
        </record>
        <record ID="3">
            <name>
                <nm:first_name>first name</nm:first_name>
                <nm:middle_name>middle name</nm:middle_name>
                <nm:last_name>last name</nm:last_name>
            </name>
            <address>
                <add:street_address>street address</add:street_address>
                <add:street_address_detail>street address detail</add:street_address_detail>
                <add:city>city</add:city>
                <add:state>state</add:state>
                <add:zipcode>94000</add:zipcode>
            </address>
            <contact>
                <con:home_phone>888-555-1212</con:home_phone>
                <con:work_phone>888-555-1212</con:work_phone>
                <con:cell_phone>888-555-1212</con:cell_phone>
                <con:email_address>user@whatever.com</con:email_address>
            </contact>
            <other_info>
                <inf:birth_date>888-555-1212</inf:birth_date>
                <inf:anniversary>888-555-1212</inf:anniversary>
                <inf:personal_website>http://www.whatver.com</inf:personal_website>
            </other_info>
            <comments>
                <com:text>Any comment about the person</com:text>
            </comments>
        </record>
        <record ID="4">
            <name>
                <nm:first_name>first name</nm:first_name>
                <nm:middle_name>middle name</nm:middle_name>
                <nm:last_name>last name</nm:last_name>
            </name>
            <address>
                <add:street_address>street address</add:street_address>
                <add:street_address_detail>street address detail</add:street_address_detail>
                <add:city>city</add:city>
                <add:state>state</add:state>
                <add:zipcode>94000</add:zipcode>
            </address>
            <contact>
                <con:home_phone>888-555-1212</con:home_phone>
                <con:work_phone>888-555-1212</con:work_phone>
                <con:cell_phone>888-555-1212</con:cell_phone>
                <con:email_address>user@whatever.com</con:email_address>
            </contact>
            <other_info>
                <inf:birth_date>888-555-1212</inf:birth_date>
                <inf:anniversary>888-555-1212</inf:anniversary>
                <inf:personal_website>http://www.whatver.com</inf:personal_website>
            </other_info>
            <comments>
                <com:text>Any comment about the person</com:text>
            </comments>
        </record>
        <record ID="5">
            <name>
                <nm:first_name>first name</nm:first_name>
                <nm:middle_name>middle name</nm:middle_name>
                <nm:last_name>last name</nm:last_name>
            </name>
            <address>
                <add:street_address>street address</add:street_address>
                <add:street_address_detail>street address detail</add:street_address_detail>
                <add:city>city</add:city>
                <add:state>state</add:state>
                <add:zipcode>94000</add:zipcode>
            </address>
            <contact>
                <con:home_phone>888-555-1212</con:home_phone>
                <con:work_phone>888-555-1212</con:work_phone>
                <con:cell_phone>888-555-1212</con:cell_phone>
                <con:email_address>user@whatever.com</con:email_address>
            </contact>
            <other_info>
                <inf:birth_date>888-555-1212</inf:birth_date>
                <inf:anniversary>888-555-1212</inf:anniversary>
                <inf:personal_website>http://www.whatver.com</inf:personal_website>
            </other_info>
            <comments>
                <com:text>Any comment about the person</com:text>
            </comments>
        </record>
    </address_book>

  2. The file above linked to a validating schema - address_book_imported_xsd.xml

    <?xml version="1.0" standalone="no"?>
    <!--Declaration of qualified locals with default namespace-->
    <!-- Created by Pushpa - 05/13/2002 Modified by RDC and Unice Change 05/31/2003 -->
    <address_book xmlns="http://www.addressbook.com" 
                  xmlns:nm="http://www.name.com" 
                  xmlns:add="http://www.address.com" 
                  xmlns:con="http://www.contact.com" 
                  xmlns:inf="http://www.otherinfo.com" 
                  xmlns:com="http://www.comments.com" 
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                  xsi:schemaLocation="http://www.addressbook.com address_book_imported.xsd 
                                      http://www.address.com addressType.xsd 
                                      http://www.contact.com contactType.xsd 
                                      http://www.name.com nameType.xsd 
                                      http://www.otherinfo.com other_infoType.xsd">
        .
        .
        .
    </address_book>

  3. The schema for the address book with custom namespaces - address book imported.xsd

    <?xml version="1.0"?>
    <!-- Using multiple xml schema - Created by: Pushpa 05/13/2002 -->
    <xsd:schema targetNamespace="http://www.addressbook.com" 
                xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                xmlns:nm="http://www.name.com" 
                xmlns:add="http://www.address.com" 
                xmlns:con="http://www.contact.com" 
                xmlns:inf="http://www.otherinfo.com" 
                xmlns:com="http://www.comments.com"  
                xmlns="http://www.addressbook.com">
        <!-- Include nametype, addresstype, contacttype, other_infotype, 
             commenttype constucts -->
        <xsd:import namespace="http://www.name.com" schemaLocation="nameType.xsd"/>
        <xsd:import namespace="http://www.address.com" schemaLocation="addressType.xsd"/>
        <xsd:import namespace="http://www.contact.com" schemaLocation="contactType.xsd"/>
        <xsd:import namespace="http://www.otherinfo.com" schemaLocation="other_infoType.xsd"/>
        <xsd:import namespace="http://www.comments.com" schemaLocation="commentsType.xsd"/>
    
        <!-- Root element is of address_booktype -->
        <xsd:element name="address_book" type="address_bookType"/>
    
        <!-- Address_booktype has an element 'recordtype'-->
        <xsd:complexType name="address_bookType">
            <xsd:sequence>
                <xsd:element name="record" type="recordType" minOccurs="0" 
                             maxOccurs="unbounded"/>
            </xsd:sequence>
        </xsd:complexType>
    
        <!-- Recordtype has elements name, address, contact, other_info, comment and an 
             attribute ID -->
        <xsd:complexType name="recordType">
            <xsd:sequence>
                <xsd:element name="name" type="nm:nameType"/>
                <xsd:element name="address" type="add:addressType"/>
                <xsd:element name="contact" type="con:contactType"/>
                <xsd:element name="other_info" type="inf:other_infoType"/>
                <xsd:element name="comments" type="com:commentsType"/>
            </xsd:sequence>
            <xsd:attribute name="ID" type="xsd:positiveInteger" use="required"/>
        </xsd:complexType>
    </xsd:schema>

  4. The schema for the name section - nameType.xsd

    <?xml version="1.0"?>
    <xsd:schema targetNamespace="http://www.name.com" 
                xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                xmlns="http://www.name.com" 
                elementFormDefault="qualified">
        <!-- nametype has elements first_name, middle_name, last_name, nick_name of 
             simpletype xsd:string -->
        <xsd:complexType name="nameType">
            <xsd:sequence>
                <xsd:element name="first_name" type="xsd:string"/>
                <xsd:element name="middle_name" type="xsd:string"/>
                <xsd:element name="last_name" type="xsd:string"/>
                <xsd:element name="nick_name" type="xsd:string" minOccurs="0"/>
            </xsd:sequence>
        </xsd:complexType>
        <!-- fictitious declaration of nick_nameType" -->
        <xsd:simpleType name="nick_nameType">
            <xsd:restriction base="xsd:string">
                <xsd:pattern value="\d{5}(-\d{4})?"/>
            </xsd:restriction>
        </xsd:simpleType>
    </xsd:schema>

  5. The schema for the address section - addressType.xsd

    <?xml version="1.0"?>
    <xsd:schema targetNamespace="http://www.address.com" 
                xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                xmlns="http://www.address.com" 
                elementFormDefault="qualified">
        <!--addressType has elements street_address, street_address_detail, city, 
            state, zipcode -->
        <xsd:complexType name="addressType">
            <xsd:sequence>
                <xsd:element name="street_address" type="xsd:string"/>
                <xsd:element name="street_address_detail" type="xsd:string"/>
                <xsd:element name="city" type="xsd:string"/>
                <xsd:element name="state" type="xsd:string"/>
                <xsd:element name="zipcode" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
        <!--zipcode has a pattern defined to restrict the user -->
        <xsd:simpleType name="zipcodeType">
            <xsd:restriction base="xsd:string">
                <xsd:pattern value="\d{5}(-\d{4})?"/>
            </xsd:restriction>
        </xsd:simpleType>
    </xsd:schema>

  6. The schema for the contact section - contactType.xsd

    <?xml version="1.0"?>
    <xsd:schema targetNamespace="http://www.contact.com" 
                xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                xmlns="http://www.contact.com" 
                elementFormDefault="qualified">
        <!-- contactType has elements, home_phone, work_phone, cell_phone and e-mail -->
        <xsd:complexType name="contactType">
            <xsd:sequence>
                <xsd:element name="home_phone" type="xsd:string" minOccurs="0"/>
                <xsd:element name="work_phone" type="xsd:string" minOccurs="0"/>
                <xsd:element name="cell_phone" type="xsd:string" minOccurs="0"/>
                <xsd:element name="email_address" type="xsd:string" minOccurs="0"/>
            </xsd:sequence>
        </xsd:complexType>
        <!-- phone has a pattern defined -->
        <xsd:simpleType name="phoneType">
            <xsd:restriction base="xsd:string">
                <xsd:pattern value="\d{3}\-\d{3}\-\d{4}"/>
            </xsd:restriction>
        </xsd:simpleType>
    </xsd:schema>

  7. The schema for the comments section - commentsType.xsd

    <?xml version="1.0"?>
    <xsd:schema targetNamespace="http://www.comments.com" 
                xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                xmlns="http://www.comments.com" 
                elementFormDefault="qualified">
        <!-- commentsType has element text which is xsd:string -->
        <xsd:complexType name="commentsType">
            <xsd:sequence>
                <xsd:element name="text" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:schema>

  8. The entire archive zipped for you to download an examine - Address_imported.zip

Section 4

In this section, a bioinformatic template for importing genomic, proteomic, and pharma elements. This project will be under continual design throughout the summer for launch in COIN79 in Fall 2004. These can be viewed as separate files or as a complete archive in zipped format

  1. An biomolecule XML file with prefixed elements and custom namespaces - biomolecule.xml
  2. The file above linked to a validating schema - biomolecule_xsd.xml
  3. The schema for the genome with custom namespaces - biomolecule.xsd
  4. The schema for the genome section - genome.xsd
  5. The schema for the proteome section - proteome.xsd
  6. The schema for the pharma section - pharma.xsd
  7. The entire archive zipped for you to download an examine - biomolecule.zip

Section 5

Animal Planet - a great set of files showing the use of threaded namespaces - Moumita Nandi

  1. animal_planet_namespace base file - animal_planet_namespace.xml
  2. animal_planet_namespace linked to a validating schema file - animal_planet_namespace_xsd.xml
  3. animal_planet_namespace schema - animal_planet_namespace schema.xsd
  4. amphibian schema - amphibian.xsd
  5. animal - animal.xsd
  6. bird - bird.xsd
  7. family - family.xsd
  8. fish - fish.xsd
  9. insect - insect.xsd
  10. mammal - mammal.xsd
  11. reptile - reptile.xsd
  12. The entire archive zipped for you to download an examine - animal planet_ns.zip

Section 6

Prefixing elements to show HTML

  1. There are different ways to add namespaces to utilize HTML image and anchor tags. This was introduced in the CSS tutorial (Week 4). Use this code for your namespace: <xmlns:html="http://www.w3.org/2001/XMLSchema"> for hyperlinks in XSL or CSS. This normally uses the MIME type text/css, but can be used inline with text/css (see below). Now you can use HTML anchors and their attributes in XML.
  2. Use this code for a hypertext link:
    <html:a href="http://www.whatever.com/">link</html:a>
  3. Use this code for placing images in XML and CSS <html:img src="image.ext"></html:img>
  4. For an example of how HTML would look in XHTML, look at the file html.htm and html_namespace.xml, the same file written in XHTML. Look at the CSS file, namespace.css.
  5. You can use namespaces to create XHTML documents using the XHTML namespace xmlns:html=”http://www.w3.org/1999/xhtml”. Look at these two XHTML files xhtml_1.xml and xhtml_2.xml to see examples of blending XML and HTML. Here are the CSS files, namespace1.css and namespace2.css.

Section 7

RDF and RSS - an introduction to XML as resource files for websites (RSS and RDF) and news feeds using RSS

  1. rdcormia.rdf - a resource file from my personal website (right click to download - will *not* open in MSIE)

    <?xml version="1.0"?>
    <rdf:RDF xmlns="http://purl.org/rss/1.0/" 
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
        <channel rdf:about="http://www.rdcormia.com/">
            <title>RD Cormia website</title>
            <link>http://www.rdcormia.com/</link>
            <description>RD Cormia website for Foothill College online courses</description>
            <items>
                <rdf:Seq>
                    <rdf:li resource="http://www.rdcormia.com/CIS61/"/>
                    <rdf:li resource="http://www.rdcormia.com/COIN78/"/>
                    <rdf:li resource="http://www.rdcormia.com/COIN79/"/>
                    <rdf:li resource="http://www.rdcormia.com/COIN81/"/>
                </rdf:Seq>
            </items>
        </channel>
        <item rdf:about="http://www.rdcormia.com/CIS61/">
            <title>CIS61 Introduction to Informatics</title>
            <link>http://www.rdcormia.com/CIS61/</link>
            <description>Website for CIS61 Introduction to Informatics</description>
        </item>
        <item rdf:about="http://www.rdcormia.com/COIN78/">
            <title>COIN78 Introduction to XML</title>
            <link>http://www.rdcormia.com/COIN78/</link>
            <description>Website for COIN78 Introduction to XML</description>
        </item>
        <item rdf:about="http://www.rdcormia.com/COIN79/">
            <title>COIN79 Introduction to XML for Biologists for Biologists</title>
            <link>http://www.rdcormia.com/COIN79/</link>
            <description>Website for COIN79 Introduction to XML</description>
        </item>
        <item rdf:about="http://www.rdcormia.com/COIN81/">
            <title>COIN81 Web databases</title>
            <link>http://www.rdcormia.com/COIN81/</link>
            <description>
                Website for COIN81 Introduction to Web bioinformatics databases
            </description>
        </item>
    </rdf:RDF>

  2. rdcormia_rdf.xml - same file as above but with an .xml extension (use the link below to generate an RSS RDF file for your website)
  3. Generate RSS 1.0 files - These pages generate RSS 1.0. See http://web.resource.org/rss/1.0/ for more detail about RSS 1.0
  4. RSS 1.0 schema - Take a look at this file (and schema.rdf) to see the XML schema for the RSS 1.0 specification

    <?xml version="1.0"?>
    <!--
    RDF Schema declaration for Rich Site Summary (RSS) 1.0 <http://purl.org/rss/1.0/>
    note: This schema currently is defining RSS-specific constructs 
    (resource and relationship types) only. No contraints have been 
    introduced.
    Note: this schema is represented in the RDF M&S abbreviated 
    syntax <http://www.w3.org/TR/REC-rdf-syntax/#abbreviatedSyntax> for 
    syntactic inclusion in an HTML/XHTML document
    -->
    <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
             xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
             xmlns:dc="http://purl.org/dc/elements/1.1/">
        <!--  Class declarations   -->
        <rdfs:Class rdf:about="http://purl.org/rss/1.0/channel" rdfs:label="Channel" 
                    rdfs:comment="An RSS information channel.">
            <rdfs:isDefinedBy rdf:resource="http://purl.org/rss/1.0/"/>
        </rdfs:Class>
        <rdfs:Class rdf:about="http://purl.org/rss/1.0/image" rdfs:label="Image" 
                    rdfs:comment="An RSS image.">
            <rdfs:isDefinedBy rdf:resource="http://purl.org/rss/1.0/"/>
        </rdfs:Class>
        <rdfs:Class rdf:about="http://purl.org/rss/1.0/item" rdfs:label="Item" 
                    rdfs:comment="An RSS item.">
            <rdfs:isDefinedBy rdf:resource="http://purl.org/rss/1.0/"/>
        </rdfs:Class>
        <rdfs:Class rdf:about="http://purl.org/rss/1.0/textinput" rdfs:label="Text Input" 
                    rdfs:comment="An RSS text input.">
            <rdfs:isDefinedBy rdf:resource="http://purl.org/rss/1.0/"/>
        </rdfs:Class>
        <!--  Property declarations  -->
        <rdf:Property rdf:about="http://purl.org/rss/1.0/items" rdfs:label="Items" 
                      rdfs:comment="Points to a list of rss:item elements that are members 
                                    of the subject channel.">
            <rdfs:isDefinedBy rdf:resource="http://purl.org/rss/1.0/"/>
        </rdf:Property>
        <rdf:Property rdf:about="http://purl.org/rss/1.0/title" rdfs:label="Title" 
                      rdfs:comment="A descriptive title for the channel.">
            <rdfs:subPropertyOf rdf:resource="http://purl.org/dc/elements/1.1/title"/>
            <rdfs:isDefinedBy rdf:resource="http://purl.org/rss/1.0/"/>
        </rdf:Property>
        <rdf:Property rdf:about="http://purl.org/rss/1.0/link" rdfs:label="Link" 
                      rdfs:comment="The URL to which an HTML rendering of the subject 
                                    will link.">
            <rdfs:subPropertyOf rdf:resource="http://purl.org/dc/elements/1.1/identifier"/>
            <rdfs:isDefinedBy rdf:resource="http://purl.org/rss/1.0/"/>
        </rdf:Property>
        <rdf:Property rdf:about="http://purl.org/rss/1.0/url" rdfs:label="URL" 
                      rdfs:comment="The URL of the image to used in the 'src' attribute of 
                      the channel's image tag when rendered as HTML.">
            <rdfs:subPropertyOf rdf:resource="http://purl.org/dc/elements/1.1/identifier"/>
            <rdfs:isDefinedBy rdf:resource="http://purl.org/rss/1.0/"/>
        </rdf:Property>
        <rdf:Property rdf:about="http://purl.org/rss/1.0/description" rdfs:label="Description" 
                      rdfs:comment="A short text description of the subject.">
            <rdfs:subPropertyOf rdf:resource="http://purl.org/dc/elements/1.1/description"/>
            <rdfs:isDefinedBy rdf:resource="http://purl.org/rss/1.0/"/>
        </rdf:Property>
        <rdf:Property rdf:about="http://purl.org/rss/1.0/name" rdfs:label="Name" 
                      rdfs:comment="The text input field's (variable) name.">
            <rdfs:isDefinedBy rdf:resource="http://purl.org/rss/1.0/"/>
        </rdf:Property>
    </rdf:RDF>

  5. RDC_RDF.xml - an RDF resource description of my website using the Dublin Core model.

    <?xml version="1.0"?>
    <!DOCTYPE rdf:RDF SYSTEM 
             "http://dublincore.org/documents/2002/07/31/dcmes-xml/dcmes-xml-dtd.dtd">
    <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
             xmlns:dc="http://purl.org/dc/elements/1.1/">
        <rdf:Description rdf:about="http://www.rdcormia.com/">
            <dc:title>Bob Cormia's Website</dc:title>
            <dc:creator>Robert D. Cormia rdcormia@earthlink.net</dc:creator>
            <dc:subject>Bob Cormia's website; Robert Cormia; Robert D. Cormia; Devin Cormia; 
                Devin Lyle Cormia; Judy Freeland; Judy Ann Freeland; Foothill College; 
                College of San Mateo; CSM; Electronic Commerce; Electronic Business; 
                Internet Marketing; Web Marketing; Internet Projects; Building a webstore; 
                UCSC HTML courses; COIN56; COIN 56; COIN58; COIN60; COIN 60; COIN72; COIN 72; 
                COIN117; COIN 117; Building a webstore</dc:subject>
            <dc:description>Bob Cormia's Website, where you can link to courses taught at 
                Foothill College in electronic commerce and bioinformatics.</dc:description>
            <dc:date>2002-12-31</dc:date>
            <dc:type>Text</dc:type>
            <dc:format>text/html</dc:format>
            <dc:format>9521 bytes</dc:format>
            <dc:language>EN english</dc:language>
        </rdf:Description>
    </rdf:RDF>

  6. Dublin Core Meta Generator - Used to generate the RDF files above. Try it on any website, especially your own. Meta tags are required.
  7. dcmes-xml-dtd.dtd - Used for the Dublin Core Meta Data Model http://dublincore.org/documents/2002/07/31/dcmes-xml/dcmes-xml-dtd.dtd

    <!--
        DTD 2002-04-22 for
        Expressing Simple Dublin Core in RDF/XML
        http://dublincore.org/documents/2002/07/31/dcmes-xml/

    Public ID: "-//DUBLIN CORE//DCMES DTD 2002/07/31//EN" Authors: Dave Beckett <dave.beckett@bristol.ac.uk> Eric Miller <emiller@w3.org> Dan Brickley <danbri@w3.org> Based on Dublin Core Metadata Element Set, Version 1.1: Reference Description http://dublincore.org/documents/1999/07/02/dces/ This DTD is for information only and NON-NORMATIVE. -->
    <!-- The namespaces for RDF and DCMES 1.1 respectively --> <!ENTITY rdfns 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' > <!ENTITY dcns 'http://purl.org/dc/elements/1.1/' > <!-- Declare convenience entities for XML namespace declarations --> <!ENTITY % rdfnsdecl 'xmlns:rdf CDATA #FIXED "&rdfns;"' > <!ENTITY % dcnsdecl 'xmlns:dc CDATA #FIXED "&dcns;"' > <!-- The wrapper element --> <!ELEMENT rdf:RDF (rdf:Description)* > <!ATTLIST rdf:RDF %rdfnsdecl; %dcnsdecl; > <!ENTITY % dcmes "dc:title | dc:creator | dc:subject | dc:description | dc:publisher | dc:contributor | dc:date | dc:type | dc:format | dc:identifier | dc:source | dc:language | dc:relation | dc:coverage | dc:rights" > <!-- The resource description container element --> <!ELEMENT rdf:Description (%dcmes;)* > <!ATTLIST rdf:Description rdf:about CDATA #IMPLIED> <!-- The elements from DCMES 1.1 The name given to the resource. --> <!ELEMENT dc:title (#PCDATA)> <!ATTLIST dc:title xml:lang CDATA #IMPLIED> <!ATTLIST dc:title rdf:resource CDATA #IMPLIED> <!-- An entity primarily responsible for making the content of the resource. --> <!ELEMENT dc:creator (#PCDATA)> <!ATTLIST dc:creator xml:lang CDATA #IMPLIED> <!ATTLIST dc:creator rdf:resource CDATA #IMPLIED> <!-- The topic of the content of the resource. --> <!ELEMENT dc:subject (#PCDATA)> <!ATTLIST dc:subject xml:lang CDATA #IMPLIED> <!ATTLIST dc:subject rdf:resource CDATA #IMPLIED> <!-- An account of the content of the resource. --> <!ELEMENT dc:description (#PCDATA)> <!ATTLIST dc:description xml:lang CDATA #IMPLIED> <!ATTLIST dc:description rdf:resource CDATA #IMPLIED> <!-- The entity responsible for making the resource available. --> <!ELEMENT dc:publisher (#PCDATA)> <!ATTLIST dc:publisher xml:lang CDATA #IMPLIED> <!ATTLIST dc:publisher rdf:resource CDATA #IMPLIED> <!-- An entity responsible for making contributions to the content of the resource. --> <!ELEMENT dc:contributor (#PCDATA)> <!ATTLIST dc:contributor xml:lang CDATA #IMPLIED> <!ATTLIST dc:contributor rdf:resource CDATA #IMPLIED> <!-- A date associated with an event in the life cycle of the resource. --> <!ELEMENT dc:date (#PCDATA)> <!ATTLIST dc:date xml:lang CDATA #IMPLIED> <!ATTLIST dc:date rdf:resource CDATA #IMPLIED> <!-- The nature or genre of the content of the resource. --> <!ELEMENT dc:type (#PCDATA)> <!ATTLIST dc:type xml:lang CDATA #IMPLIED> <!ATTLIST dc:type rdf:resource CDATA #IMPLIED> <!-- The physical or digital manifestation of the resource. --> <!ELEMENT dc:format (#PCDATA)> <!ATTLIST dc:format xml:lang CDATA #IMPLIED> <!ATTLIST dc:format rdf:resource CDATA #IMPLIED> <!-- An unambiguous reference to the resource within a given context. --> <!ELEMENT dc:identifier (#PCDATA)> <!ATTLIST dc:identifier xml:lang CDATA #IMPLIED> <!ATTLIST dc:identifier rdf:resource CDATA #IMPLIED> <!-- A Reference to a resource from which the present resource is derived. --> <!ELEMENT dc:source (#PCDATA)> <!ATTLIST dc:source xml:lang CDATA #IMPLIED> <!ATTLIST dc:source rdf:resource CDATA #IMPLIED> <!-- A language of the intellectual content of the resource. --> <!ELEMENT dc:language (#PCDATA)> <!ATTLIST dc:language xml:lang CDATA #IMPLIED> <!ATTLIST dc:language rdf:resource CDATA #IMPLIED> <!-- A reference to a related resource. --> <!ELEMENT dc:relation (#PCDATA)> <!ATTLIST dc:relation xml:lang CDATA #IMPLIED> <!ATTLIST dc:relation rdf:resource CDATA #IMPLIED> <!-- The extent or scope of the content of the resource. --> <!ELEMENT dc:coverage (#PCDATA)> <!ATTLIST dc:coverage xml:lang CDATA #IMPLIED> <!ATTLIST dc:coverage rdf:resource CDATA #IMPLIED> <!-- Information about rights held in and over the resource. --> <!ELEMENT dc:rights (#PCDATA)> <!ATTLIST dc:rights xml:lang CDATA #IMPLIED> <!ATTLIST dc:rights rdf:resource CDATA #IMPLIED>

  8. rss.xml - an RSS file from Apple iTunes. This is RSS as 'Really Simple Syndication', rather than 'Rich Site Summary'.

Homework

Add namespaces to your schema document from last week, even if it is just a practice file. This can be tricky, so stay organized, and use the example files as 'patterns' until you can follow the flow of how all this comes together. Namespaces can be a *very* powerful tool.


Powerpoint Presentations

Links to XML Related Sites

  1. XML.COM
  2. WDVL XML tutorial
  3. Sun Java XML Introduction
  4. IBM'S XML Website
  5. Google Directory on XML

 


Copyright © 2009 - 2010 Robert D. Cormia - June 26, 2010