URI Templates in XML

One of the obvious and important aspects of URI Templates is how to express templates and their collection of template variables within XML. The two cases where this becomes immediately important are OpenSearch and CalAtom. There has been some recent discussion on this topic and after talking it over with Joe and DeWitt a bit, I’m leaning towards the following approach.

  <template rel="..." xmlns:t="http://.../template-variables"
    t:searchTerms="http://example.org/variables#SearchTerms"
    t:count="http://example.org/variables#Count"
    pattern="http://example.com/search?q={searchTerms}&c={count}" />

The short explanation is:

  • The xmlns:t namespace would be some commonly understood namespace used to define template variable names.
  • Each t: prefixed attribute is a template variable. The IRI value of the attribute unambiguously identifies the variable definition.
  • When presented with the pattern, processors would know to go looking for attributes in the “http://…/template-variables” namespace to determine the meaning of the template-variables.

The approach completely bypasses the problem of using QNames within attribute values in XML.

The t: attribute definitions could be inherited to reduce verbosity, e.g.,

  <a xmlns:t="http://.../template-variables"
    t:searchTerms="http://example.org/variables#SearchTerms"
    t:count="http://example.org/variables#Count">
    <template rel="..."
      pattern="http://example.com/search1?q={searchTerms}&c={count}" />
    <template rel="..."
      pattern="http://example.com/search2?q={searchTerms}&c={count}" />
  </a>

Comments are closed.