If you know HTML, you also know XML, the Extensible Markup Language—just think of it as HTML where you can invent and specify your own tags.
To be more specific, XML is a general-purpose markup language, which means that you can describe and annotate the structure or formatting of text with it. HTML is a particular example of XML used to describe the structure and formatting of a web page.
Using XML, you can define a set of tags that together form a vocabulary for a specific subject. This is great if in all XML documents you would only need tags from one vocabulary, but probably you can imagine that this would be rather restrictive.
In this section, we give some background for the use of XML namespaces in the Backbase framework. As the W3C standard puts it, XML namespaces provide a simple method for qualifying element and attribute names used in Extensible Markup Language documents by associating them with namespaces identified by URI references.
When XML was invented, there was no such thing as a namespace concept. The steadily increasing volume of XML data that was exchanged between different groups of people and different companies revealed a series of problems. One was that it was difficult to properly combine parts of different XML documents into new documents. Basically, these are the causes:
An XML vocabularies collision problem. This means that two XML documents could have tags with the same name, while in each document this tag could have a different meaning or structure. For example, a
<language>
tag could have an attributeversion
if it is a programming language, or else an attributeregion
, to indicate where this particular form of natural language is spoken.An intended content recognition problem. This means that if I see a tag in a document that has tags from more than one vocabulary, I need to know to which vocabulary it belongs. For example, if you see a
<title>
tag, is this the title of a book, the title in an HTML document, or the title of a person, such as "Mrs." or "professor"? Similarly, is a<border>
the border of a country or a border of an element on a web page?
In order to solve these issues, the mechanism of namespaces was introduced into XML. If you are familiar with a programming language like Java, the namespace concept is similar to the package concept in that language. It enabled authors to determine, on markup, vocabularies for their content and facilitated governance.
You can recognize an XML namespace when you see an attribute that starts with xmlns
. The part of the attribute that follows xmlns:
is called a prefix. It is that part of the namespace declaration that actually sets up a link between a convenience token and a namespace. The namespace declaration scope is limited to the element where it was done and to the element's sub-tree. The names of these attributes are reserved: you cannot use an xmlns
attribute or prefix for another purpose.
Let's consider a sample XML document that uses namespaces:
<?xml version="1.0"?> <catalog xmlns="http://www.library.com/ns/catalog" xmlns:isbn="http://www.isbn.com/ns/isbn"> <book isbn:id="1847196705" id="1"> <title>Learning jQuery</title> <author>Karl Swedberg</author> <author>Jonathan Chaffer </author> <isbn:datePublished>February 2009</isbn:datePublished> </book> <book isbn:id="1847191444" id="2"> <title>Joomla! Template Design</title> <author>Tessa Blakeley Silver</author> <isbn:datePublished>June 2007</isbn:datePublished> </book> <!-- More books --> </catalog>
The catalog could serve as a description of books in a local library. The meaning and structure of the tags can be whatever the local library thinks is practical. In this document there is also the isbn
namespace, which is used for tags that are relevant to the worldwide book register that the International Standard Book Number (ISBN) represents.
The Backbase Client Runtime processes all the tags that are placed between script
tags that have type="text/backbase+xml"
as attribute. To the Backbase Client Runtime, the combination of the namespace and the tag name will determine what the engine will do to interpret the tag.
We call a set of tags that belong to a specific namespace a markup language. In the Backbase point of view, XHTML is just another markup language. It belongs to the http://www.w3.org/1999/xhtml namespace, which you must declare just like the specific Backbase namespaces.
We have already seen several namespaces in our examples. Below is a list of namespaces you can expect to be using with Backbase, together with their preferred prefixes:
xmlns = "http://www.w3.org/1999/xhtml" xmlns:xi = "http://www.w3.org/2001/XInclude" xmlns:xs = "http://www.w3.org/2001/XMLSchema" xmlns:smil = "http://www.w3.org/2005/SMIL21/" xmlns:b = "http://www.backbase.com/2006/btl" xmlns:c = "http://www.backbase.com/2006/command" xmlns:d = "http://www.backbase.com/2006/tdl" xmlns:e = "http://www.backbase.com/2006/xel" xmlns:bf = "http://www.backbase.com/2007/forms"
Although it is legal to use different prefixes bound to the same namespace URI in different documents as well as within the same document, it is often convenient to stick to using similar ones.
For each markup language in your application, you must add a namespace declaration. For example, if you are using BTL UI widgets, you will need to add a BTL namespace declaration to your document.
The engine does recognize namespace declarations placed outside its processing space. This means that the best place to declare namespaces for all languages processed by the Client Runtime is as high as possible in the DOM tree, for example the <html>
tag.
Note
Each XML document, even if it will be included into another document, must contain appropriate namespace declarations.
Here is an example of namespace declarations that you could use with some of the Backbase markup languages:
<script xmlns="http://www.w3.org/1999/xhtml" xmlns:b="http://www.backbase.com/2006/btl" xmlns:e="http://www.backbase.com/2006/xel" xmlns:xi="http://www.w3.org/2001/XInclude" type="application/backbase+xml"> <div> Given the correct widget prefixes, the Client Runtime can now process all XHTML, BTL, XEL, and XInclude elements. XHTML is the default namespace, so we don't have to give a prefix to the parent div tag. </div> </script>
Using namespaces in your application can be confusing at first and can be a source of problems for a Backbase beginner. A good piece of advice is to check your namespaces if you have an error that you do not understand. Soon, adding the right namespaces will become second nature.