XML Namespaces Primer

The following question recently came to me via email:

I am looking at the XBRL files http://www.sec.gov/Archives/edgar/data/27419/000104746913003100/0001047469-13-003100-index.htm which describe a 10-K statement for Target. In the stock holder equity one of the values was associated with a name that was “tgt:AccumulatedOtherComprehensiveIncomeLossForeignCurrencyTranslationAdjustmentAndCashFlowHedgesNetOfTax”. Where did the tgt tag come from? Was it made up, and how would I know to include it on any particular company’s balance sheet?

The answer has to do with a design feature of XML called XML namespaces. XBRL is built on top of XML, and an understanding of XML is helpful when dealing with XBRL documents and their associated files.

XML elements are defined in a file called a schema. The schema defines the elements that can legally appear in a document that is supposed to conform to the schema. A schema is, in a sense, a data dictionary for the allowable elements that can appear in an XML document that is supposed to adhere to the schema.

Schemas can be designed by anyone, at any time, and for any reason. It is entirely possible that two companies designing a schema may use the same element name. Company A, for example, may construct a schema which states that XML documents that adhere to Company A’s schema can use an element called <asset>. Company B, however, working independently, with no knowledge of what Company A is doing, might also construct a schema which states that XML documents that adhere to Company B’s schema can also use an element called <asset>. This is all valid XML, but the question becomes this: when examining an XML document, and upon seeing an element called <asset>, how do you determine whether the <asset> element is actually Company A’s <asset> element or Company B’s <asset> element?

The answer is to prefix the element name with a namespace identifier that describes the element as belonging to Company A or Company B. If the namespace describes the element with the Company A prefix, then you know that the element is bound to Company A’s schema. If, however, the namespace describes the element with the Company B prefix, then you know that the element is bound to Company B’s schema.

Let’s examine this using the concrete example used in the original question. XML schemas traditionally have an extension of XSD, and, in looking at the Target 10-K files at http://www.sec.gov/Archives/edgar/data/27419/000104746913003100/0001047469-13-003100-index.htm, we see a file called tgt-20130202.xsd. A-ha! Let’s open that up and take a look. The root element in this schema (which, by the way,┬áis itself an XML document) looks like this:

<xsd:schema xmlns:xlink=”http://www.w3.org/1999/xlink&#8221; xmlns:us-gaap=”http://fasb.org/us-gaap/2012-01-31&#8243; xmlns:attributeFormDefault=”unqualified” attributeFormDefault=”unqualified” xmlns:xbrli=”http://www.xbrl.org/2003/instance&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xmlns:xl=”http://www.xbrl.org/2003/XLink&#8221; xmlns:negated=”http://www.xbrl.org/2009/role/negated&#8221; xmlns:dei=”http://xbrl.sec.gov/dei/2012-01-31&#8243; xmlns:xbrldt=”http://xbrl.org/2005/xbrldt&#8221; xmlns:nonnum=”http://www.xbrl.org/dtr/type/non-numeric&#8221; xmlns:num=”http://www.xbrl.org/dtr/type/numeric&#8221; xmlns:ref=”http://www.xbrl.org/2006/ref&#8221; xmlns:link=”http://www.xbrl.org/2003/linkbase&#8221; xmlns:us-types=”http://fasb.org/us-types/2012-01-31&#8243; xmlns:tgt=”http://www.target.com/20130202&#8243; xmlns:xsd=”http://www.w3.org/2001/XMLSchema&#8221; elementFormDefault=”qualified” targetNamespace=”http://www.target.com/20130202″&gt;

The first item to take note is the targetNamespace attribute, which looks like this:

targetNamespace=http://www.target.com/20130202

(Note that “target” here is referring to the generic word “target”, as in “this current schema”, or “default namespace”, and has nothing to do with Target Corporation. All XML schemas will have a “targetNamespace” element, regardless of the schema entity’s name.)

The value of the attribute is

http://www.target.com/20130202

That looks like a URL to a Web page, but it is not. It is simply a generic identifier. Navigating to that URL from a Web browser won’t get you very far.

The next step is to find another attribute in the same schema definition with the same value. For this schema, it is this:

xmlns:tgt=”http://www.target.com/20130202&#8243;

That URL in the value looks familiar, does it not? That’s right. It matches the URL in the targetNamespace attribute. The attribute name is interesting, in that it has a colon in it. The “xmlns” prefix is a generic XML key that basically says “this attribute defines an XML namespace”. The value after the colon is the name of the namespace, so the key of “xmlns:tgt” can be read as “the XML namespace with the name tgt”.

If you put the two attributes together, we read it as “this schema has a default namespace URL of http://www.target.com/20130202 and its name is tgt”. We know that these two attributes tie together because they have the same URL value.

With this, we are getting to the answer to the question. When we see “tgt” as a namespace prefix in an XML document, such as in tgt:AccumulatedOtherComprehensiveIncomeLossForeignCurrencyTranslationAdjustmentAndCashFlowHedgesNetOfTax, we know that the element is defined in the Target schema. We know this because of three pieces of information:

  1. The namespace prefix in the element name is “tgt”.
  2. The “tgt” namespace has a value of http://www.target.com/20130202.
  3. The default namespace of the Target XML schema is also http://www.target.com/20130202.

Given this information, we know that there is a definition of the AccumulatedOtherComprehensiveIncomeLossForeignCurrencyTranslationAdjustmentAndCashFlowHedgesNetOfTax element somewhere in the Target schema XSD file.

For completeness, let’s take another example from the same schema element. The schema element also declares this namespace:

xmlns:link=http://www.xbrl.org/2003/linkbase

Read this definition in the same way: any element in the XML document that uses a prefix of “link” matches the schema, available somewhere on the Internet or in a specification somewhere, whose target namespace is http://www.xbrl.org/2003/linkbase. Find the XML schema that has a targetNamespace attribute value of http://www.xbrl.org/2003/linkbase, and you have found the schema that defines the element.