Welcome to Bucaro TecHelp!

Bucaro TecHelp
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Victims of Sandy Hook

Stop the Slaughter of Innocents. Congress is bought and paid for by gun lunatics and gun promotion groups. If you want to live in a safe America, help buy Congress back for America. Send a donation to Mayors Against Illegal Guns, 909 Third Avenue, 15th Floor New York, NY 10022


XML Namespaces Made Simple

XML (Extensible Markup Language) is a very powerful language becuase it can be used to create databases that are well formed and human readable. But if you're going to use your XML file for more than just your own local purposes, and exchange it with other organizations, you need a way to validate the XML.

The Document Type Definition (DTD) language was created for that purpose. However DTD has limited support for datatypes. For example it has no way to specify a type as numeric. It has only PCDATA (Parsed Character DATA). Also DTDs have no notation for namespaces. For this reason, on 2 May 2001 the W3C XML Schema 1.0 specification was released.

Namespaces are a source of much complexity and confusion in XML. Why do we need namespaces? Lets consider the XML tag <name>. Maybe it refers to a person's name, maybe the name of a book, maybe a product name. If you use your XML file for just your own local purposes, you know what it refers to, but if you're going to exchange your XML file with other organizations, you need to be more specific. A namespace is a set of names in which all names are unique. We could use the following system.

employee.name
book.name
product.name

The part before the dot would be the namespace. This clears things up a little, but what if several organizations have XML files using the <employee.name>,<book.name>, or <product.name> XML tag? As you can see these names are still not unique enough. The W3C XML Schema 1.0 specification requires XML namespace identifiers to conform to a specific syntax — the syntax for Uniform Resource Identifier (URI) references.

A URI is string of characters for identifying an abstract or physical resource. In most situations, URI references are used to identify physical resources (Web pages, files to download, and so on), but in the case of XML namespaces, URI references identify abstract resources, specifically, namespaces.

There are two forms of URI: Uniform Resource Locators (URL) and Uniform Resource Names (URN). Either type of URI may be used as a namespace identifier.

Shown below are examples of URLs that could be used as namespace identifiers:

http://www.bucarotechelp.com/staff/
http://www.ed.gov/elementary/students

Shown below are examples of URNs that could be used as namespace identifiers:

urn:www-bucarotechelp-com:student
urn:www.ed.gov:elementary.students
urn:uuid:F8F7B313-EF05-E33-4A6C-DB49A6CF88C4

Because of their specificity and length, URLs can be assumed to be unique identifiers. But to guarantee uniquess you would use a URN. Authors must register their URN namespace identifier with an Internet naming authority.

Using Namespaces

XML processors treat namespace identifiers as inactive strings and never actually attempt to access the resource identified by the URI. So it really doesn't matter what you use as a URI, as long as it has the length required to be unique. However most XML namespaces are defined in formal specifications that describe the names of elements and attributes along with their semantics.

The XML Schema working group (http://www.w3.org/XML/Schema) has put together a specification (XML Schema) that defines an XML-based syntax for defining elements, attributes, and types in a namespace.

<schema xmlns="http://www.w3.org/2000/10/XMLSchema"
   targetNamespace="http://www.bucarotechelp.com/student"
   elementFormDefault="qualified">
  <element name="student">
     <complexType>
         <sequence>
            <element name="id" type="long"/>
            <element name="name" type="string"/>
            <element name="language" type="string"/>
            <element name="rating" type="double"/>         
         </sequence>
     </complexType>
   </element>
</schema>

The example schema shown above defines the namespace http://www.bucarotechelp.com/student as containing four named elements: student, id, name, language, and rating. In addition to providing a namespace, this schema also provides metadata, such as the order of student child elements and their datatypes.

RSS Feed RSS Feed


Follow Stephen Bucaro Follow @Stephen Bucaro


Programming Sections

Fire HD
[Site User Agreement]  [Advertise on This site]  [Search This Site]  [Contact Form]
Copyright©2001-2010 Bucaro TecHelp P.O.Box 18952 Fountain Hills, AZ 85269