By Tim Dexter-Oracle on Aug 14, 2008
In the Google Maps entry from a few daze back I mentioned that to use the XML coming from the Google API I needed to get funky in the template because of the XML format. I have had two inquiries this week about how to handle an empty namespace, so I thought I'd break out those paragraphs into an article.
the XML in question starts.
<name>500 Oracle Parkway</name>
Looks innocuous enough but that first line will trip up the unwary RTF template developer. Its a namespace declaration, but you support namespaces right? They just need to be declared in the top of the template and then use the namespace prefix when referencing the elements in the XML. For instance, the following XML
can be handled by declaring the namespace in the template thus:
and then using 'inv' as a prefix to every data reference e.g.
But this Google namespace has a problem - there is no prefix
So how can you handle it? We just need to provide a dummy prefix in our template, for instance, in our template we declare..
Note there are no quotes.
we then need to prefix all of our element names with 'x:'
I know, you're asking what the heck do we need namespaces for in the first place? A kind Wikipedia soul has stated:
'In general, a namespace is an abstract container providing context for the items (names, or technical terms, or words) it holds and allowing disambiguation of items having the same name (residing in different namespaces).'
'Disambiguation'? is that a word? Basically, namespaces allow you to uniquely identify a set of names so that there is no ambiguity when objects having different origins but the same names are mixed together.
you can not discern between the INVOICE values however with the use of a namespace
we can now reference the two NUMBER elements, they are distinct from each other.
So, why do Google have an empty namespace? This might be down to the developer at Google that wrote the code neglected to specify a prefix. Maybe it was done to keep me awake when I blogged it either way, we can and now you can handle it :0)