Sign in to join Michael Dupre's fan club.
A Good Explanation Relating To Namespaces In XML
by Michael Dupre(2)
Greetings, i'm Michael Dupre. This is my '5 minute XML' tutorials where I provide regular byte size guides.
Today's topic is the platform for individuals who definitely are who is new to XML.
What constitutes a good XML name had been briefly mentioned within a former 5 minute tutorial. This type of an XML name in its self is certainly not always adequate, however. Cases may well show up by which XML names could end up ambiguous.
Suppose, for example, that a few and / or a lot more XML files are merged. The files may perhaps contain more than one author as well as at at a minimum one of the XML names might possibly have been defined in more than one of the merged files. This brings about a prospective conflict. To help demonstrate the problem evaluate the following mark-up:
[table]
[tr]
[td>item1
[td]item2[/td]
[/tr]
[/table]
[table]
[name]Dining Room Table[/name]
[length]2000[/length]
[width]1000[/width]
[height]500[/height]
[/table]
When there's only one ‘table’ component defined, we have lucidity. The moment we merge a second ‘table’ element definition next to the first, we are now no longer able to ascertain the meaning of one out of the other.
The main situation in which the two element descriptions operate now involves deeper qualification. You can easily, obviously, rename one of the conflicting elements however in a huge document and where there could possibly be many such identical names, this is actually no longer a plausible exercise.
The problem is sorted quite simply through the use of ‘namespaces’. Namespaces not simply gives you differentiation between duplicate XML names but will also achieves the key duty of making unique groups to which XML entities belong.
[root
xmlns:h="http://www.w3.org/TR/html4/"
xmlns:ct="http://www.thefurniturestore.com/coffeetables"]
[h:table]
[h:tr]
[h:td]item1[/h:td]
[h:td]item2[/h:td]
[/h:tr]
[/h:table]
[ct:table]
[ct:name]Dining Room Table[/ct:name]
[ct:length]2000[/ct:length]
[ct:width]1000[/ct:width]
[ct:height]500[/ct:height]
[/ct:table]
[/root]
Just how namespaces work is that each element (or attribute) classification is specified a prefix. Furthermore this is segregated from what is known as the ‘local part’ of the name, by way of a single colon (as shown above). It's quite common practise to affiliate a prefix with a URI (or Uniform Resource Indicator). The most prevalent kind is a URL (or Uniform Resource Locator). The URI is definitely not used with regard to lookup over the internet. Its usage is actually purely to identify a set of data objects distinctively and also, since URI’s are utilized globally they work well for the job. URI’s are bound to a namespace prefix utilising the
xmlns:prefix="URI".
Typically the prefix and the full URI definition are usually not interchangeable as URI’s can have characters that happen to be illegal in an XML namespace. It's also illegal make use of the 3 letters XML in any case grouping for a namespace prefix as these are reserved.
I'm hoping this has gone someway to teach the very idea of namespaces however I highly advise further looking at on this theme, as with all my 5 minute XML tutorials.
An abundance of details are available on XML for many who would wish to find out more. For the definitive guide, visit www.W3.org.
I'm hoping the above is useful to someone out there. Extra content will likely be on its way soon.
Michael Dupre undoubtedly an experienced guru in XML coding and XML standards and possesses an array of working know-how about XML Editor and also useful know how with XML Schema Editor.
Article submitted Wednesday, July 20, 2011 & read 11 times.
Leave your comments through Blogz:
No comments yet.
2-0-0-0-2-ADSO
Copyright © 2012 IcoLogic, Inc.