Empty Namespaces

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.

<kml xmlns="http://earth.google.com/kml/2.0">
<Response>
<name>500 Oracle Parkway</name>
<Status>
<code>200</code>
<request>geocode</request>

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

<INVOICES inv="http://www.oracle.com/xml/2.0">
<INVOICE>
<NUMBER>1001021</NUMBER>

can be handled by declaring the namespace in the template thus:

<?namespace:inv="http://www.oracle.com/xml/2.0">

and then using 'inv' as a prefix to every data reference e.g.

<?inv:INVOICE?>

But this Google namespace has a problem - there is no prefix

<kml xmlns="http://earth.google.com/kml/2.0">

So how can you handle it? We just need to provide a dummy prefix in our template, for instance, in our template we declare..

<?namespace:x=http://earth.google.com/kml/2.0>


Note there are no quotes.

we then need to prefix all of our element names with 'x:'

<?x:coordinates?>

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.

For example:

<INVOICES >
<INVOICE>
<NUMBER>1001021</NUMBER>
<NUMBER>1001011</NUMBER>

you can not discern between the INVOICE values however with the use of a namespace

<INVOICES inv="http://www.oracle.com/xml/2.0">
<INVOICE>
<NUMBER>1001021</NUMBER>
<inv:NUMBER>1001011</NUMBER>

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)

Comments:

Mouth-watering blog post!!! Wikileaks could probably give us some more background on this one.

Posted by letterofcredit on July 26, 2010 at 01:01 PM MDT #

What a comment!! Very informative also easy to understand. Looking for more such blog posts!! Do you have a twitter or a facebook? I recommended it on digg. The only thing that it's missing is a bit of color. However thank you for this blog.

Posted by Miquel Astle on August 30, 2010 at 03:00 PM MDT #

Thanks for puting this issue on blog with resolution. We also faced the same issue and were not able to understand why data was showing up in the report. Finally your blog helped to resolve the issue.

Thanks a lot.
Nitish

Posted by Nitish Gupta on July 21, 2011 at 05:19 PM MDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Follow bipublisher on Twitter Find Us on Facebook BI Publisher Youtube ChannelDiscussion Forum

Join our BI Publisher community to get the most and keep updated with the latest news, How-to, Solutions! Share your feedback and let us hear your voice @bipublisher on Twitter, on our official Facebook page, and Youtube!

Search

Archives
« March 2015
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    
       
Today