Tecnologías XML / XML / XML in a Nutshell / XLinks / URI base

(Extracto de «XML in a Nutshell» de Elliotte Rusty Harold & W. Scott Means)

Las referencias relativas como sark.jpg, ../pi1/sark.jpg y turing/pi1/sark.jpg necesitan un URI base absoluto. En XLinks, instrucciones xml-stylesheet, identificadores de sistema y otros lugares, se resuelven respecto a la URL absoluta del documento o entidad. En un documento en "http://www.turing.org.uk/turing/index.html", el elemento <image xlink:type="simple" xlink:href="pi1/sark.jpg"/> indica el archivo sark.jpg en "http://www.turing.org.uk/turing/p1/sark.jpg". Nada nuevo: HTML funciona así desde hace más de una década.

XML añade complicaciones. Un documento puede reunir varias entidades de URL o servidores distintos. Cada referencia utiliza la base de su entidad, no la del documento.

El documento también puede redefinir la base con atributos xml:base. Pueden estar en el elemento XLink o sus antepasados de la misma entidad. Este XLink apunta a ftp://ftp.knowtion.net/pub/mirrors/gutenberg/etext93/wizoz10.txt:

<novel xmlns:xlink="http://www.w3.org/1999/xlink" xml:base="ftp://ftp.knowtion.net/pub/mirrors/gutenberg/etext93/" xlink:type="simple" xlink:href="wizoz10.txt">
  <title>The Wonderful Wizard of Oz</title>
  <author>L. Frank Baum</author>
  <year>1900</year>
</novel>

Este también:

<novel xmlns:xlink="http://www.w3.org/1999/xlink" xml:base="ftp://ftp.knowtion.net/" xlink:type="simple" xlink:href="/pub/mirrors/gutenberg/etext93/wizoz10.txt">
  <title>The Wonderful Wizard of Oz</title>
  <author>L. Frank Baum</author>
  <year>1900</year>
</novel>

Y este:

<series xml:base="ftp://ftp.knowtion.net/">
  <title>Oz Books</title>
  <author>L. Frank Baum</author>
  <novel xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="/pub/mirrors/gutenberg/etext93/">
    <title>The Wonderful Wizard of Oz</title>
    <year>1900</year>
  </novel>
  ...
</series>

Todos apuntan a ftp://ftp.knowtion.net/pub/mirrors/gutenberg/etext93/wizoz10.txt sin importar el origen del documento. El atributo más cercano xml:base de la misma entidad prevalece sobre la URL base de la entidad contenedora.

xml:base también puede ser relativo. Se resuelve con una base superior o la de la entidad. Aquí, resolver los atributos xlink:href del elemento authors requiere las URL de tres antepasados:

<authors xml:base="http://www.literature.org/authors/" xmlns:xlink="http://www.w3.org/1999/xlink">
  <author xml:base="baum-l-frank/">
    <name>L. Frank Baum</name>
    <novel  xml:base="the-wonderful-wizard-of-oz/">
      <title>The Wonderful Wizard of Oz</title>
      <year>1900</year>
      <chapter xlink:type="simple" xlink:href="introduction.html">Introduction</chapter>
      <chapter xlink:type="simple" xlink:href="chapter-01.html">The Cyclone</chapter>
      <chapter xlink:type="simple" xlink:href="chapter-02.html">The Council with the Munchkins</chapter>
      ...
    </novel>
  </author>
</authors>

Si la raíz tiene una base relativa o ningún atributo xml:base? Utilice la URL absoluta de la entidad contenedora. En teoría procede de algún lugar. Pero algunas API pierden la URL o crean documentos en memoria sin base, impidiendo resolverla completamente. Las especificaciones son ambiguas; una interpretación toma la cadena vacía, el URI del documento actual. Con archivos o URL reales, cada elemento debería tener una base absoluta resoluble.

Repitamos este punto sutil: la resolución queda en una entidad, no en todo el documento. Cada entidad tiene su base. Los atributos xml:base solo se aplican en su entidad. Si A incluye B, ningún atributo xml:base de A resuelve las URL de B. Si los atributos xml:base de B no bastan, su URL de carga es la última base absoluta. xml:base de antepasados de otras entidades se ignora.

Aunque nos centramos en atributos xml:base que actúan sobre xlink:href, también funcionan en otros lugares, incluidos XInclude y XHTML 2.0. xml:base llegó tarde y no es universal. XHTML 1.0 y 1.1 ignoran atributos xml:base al resolver URL relativas en elementos a y img. Utilizan en su lugar los elementos clásicos base en el elemento del documento head.

  

<< atrás

siguiente >>

 

 

 

volver arriba