Select Page

I came across a question in ExpertsExchange the other day that was asking for help with some ribbon customisations. They always start with an XML namespace declaration which is a URI and the user wondered why the URI didn’t load anything in a browser.

It got me thinking “why not?”

For the record, these are the two XML schema declarations used by all Office ribbon customisations (as of Office 2016):


<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">

Why use a namespace?

Stepping back for a minute, XML is a language framework to define markup languages, the most common of which is HTML as used in the creation of web pages. A developer could create an XML language for absolutely anything but element and attribute names need to be unique otherwise XML parsers (the programs that interpret the XML) would get confused. So namespaces are used to declare the elements as being associated with a particular XML schema. A schema language for expressing constraints about XML documents such as a definition of the language’s elements, attributes, values and syntax rules.

For example, we might want to define an XML schema that describes furniture:

<furniture>
  <table name="Rustic Oak">
    <seats>6</seats>
    <length>180</length>
    <height>75</height>
    <width>90</width>
  </table>
</furniture>

But if you’re familiar with the HTML used to define a web page, you may have spotted that the <table> element is used in HTML to lay content out in, well, a table. This means we have an element name conflict. So how does the XML parser (the code that interprets what to do with the XML) know that we’re talking about a physical table and not a table in a document?

This is where namespaces come in.

Let’s rewrite our code using a unique namespace prefix for furniture:

<f:furniture>
  <f:table name="Rustic Oak">
    <f:seats>6</f:seats>
    <f:length>180</f:length>
    <f:height>75</f:height>
    <f:width>90</f:width>
  </f:table>
</f:furniture>

It’s as easy as prefixing all elements with “f:” but we need one more thing. We need to declare that namespace using a unique reference. Making a unique reference is easy if we simply adopt a URI based on a domain we own. So we could do this:

<root xmlns:f="http://youpresent.co.uk/schemas/furniture">
  <f:furniture>
    <f:table name="Rustic Oak">
      <f:seats>6</f:seats>
      <f:length>180</f:length>
      <f:height>75</f:height>
      <f:width>90</f:width>
     </f:table>
  </f:furniture>
</root>

or simply use the default xmlns declaration like this in order to avoid having to prefix all of our elements:

<furniture xmlns="http://youpresent.co.uk/schemas/furniture">
  <table name="Rustic Oak">
    <seats>6</seats>
    <length>180</length>
    <height>75</height>
    <width>90</width>
  </table>
</furniture>

This is where we discover that the xmlns URI is never used by the XML parser as a look-up to discover the rules about decoding the XML code we’re writing. It just has to be a globally unique text reference to avoid anyone else creating a conflict with our XML scheme definition. For example, if you visit http://youpresent.co.uk/schemas/furniture you’d find that no page was found and that’s quite all right because the XML parser doesn’t care.

However, some companies, developers, publishers will post useful information about the XML Schema at the xmlns URI.

So what’s this got to do with the Microsoft Office Ribbon?

Coming back to the article title, Microsoft use the following namespaces for the customUI declaration in their Office suite:


<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">

If you paste either of these URIs into a web browser, you’ll get a less than helpful “there’s nothing here” kind of message. But that doesn’t mean the URI in invalid. Recall the purpose of the xmlns is to create a globally unique reference for the XML Schema. The actual definition of the schema is known internally to the XML parser which may or may not use another URI to lookup the rules of the schema.

For reference, the actual schema definitions for the customUI namespaces above can be found here:

https://msdn.microsoft.com/en-us/library/dd909370(v=office.12).aspx

https://msdn.microsoft.com/en-us/library/cc313070(v=office.12).aspx

I hope this helps demystify the black art of namespaces and why Microsoft’s don’t appear to work!