The presentation of this document has been augmented to identify changes from a previous version. Three kinds of changes are highlighted: new, added text, changed text, and deleted text.


XML Base (Second Edition)

W3C Recommendation 28 January 2009

This version:
Latest version:
Previous versions:
Jonathan Marsh, Microsoft <>
Richard Tobin, University of Edinburgh <>

Please refer to the errata for this document, which may include normative corrections.

See also translations.

This document is also available in these non-normative formats: HTML with diff markup and XML.


This document proposes describes a facility, similar to that of HTML BASE, for defining base URIs for parts of XML documents.

Status of this Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at

This document has been produced by the W3C XML Core Working Group as part of the W3C XML Activity. The English version of this specification is the only normative version. However, for translations of this document, see

This document is an Edited Recommendation of the W3C. It supersedes the previous W3C Recommendation of 27 June 2001. This second edition is not a new version of XML Base; its purpose is to clarify a number of issues that have become apparent since the first edition was published. Some of these were first published as separate errata (, others were published in a public editor's draft in November 2006 (, and a PER in December 2006 ( The changes are summarized in an appendix.

Please report errors in this document to the public mailing list; public archives are available.

There is no implementation report or test suite for this specification, but there is a document describing methods of testing XML Base conformance.

This document has been reviewed by W3C Members, by software developers, and by other W3C groups and interested parties, and is endorsed by the Director as a W3C Recommendation. It is a stable document and may be used as reference material or cited from another document. W3C's role in making the Recommendation is to draw attention to the specification and to promote its widespread deployment. This enhances the functionality and interoperability of the Web.

This document is governed by the 24 January 2002 CPP as amended by the W3C Patent Policy Transition Procedure. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

Table of Contents

1 Introduction
2 Terminology
3 xml:base Attribute
    3.1 URI Reference Encoding and Escaping
4 Resolving Relative URIs
    4.1 Relation to RFC 3986
    4.2 Granularity of base URI information
    4.3 Matching URIs with base URIs
    4.4 Interpretation of same-document references
5 Conformance


A References
B References (Non-Normative)
C Impacts on Other Standards (Non-Normative)
D Changes since the first edition (Non-Normative)

1 Introduction

The XML Linking Language [XLink] defines Extensible Markup Language (XML) 1.0 [XML] constructs to describe links between resources. One of the stated requirements on XLink is to support HTML [HTML 4.01] linking constructs in a generic way. The HTML BASE element is one such construct which the XLink Working Group has considered. BASE allows authors to explicitly specify a document's base URI for the purpose of resolving relative URIs in links to external images, applets, form-processing programs, style sheets, and so on.

This document describes a mechanism for providing base URI services to XLink, but as a modular specification so that other XML applications benefiting from additional control over relative URIs but not built upon XLink can also make use of it. The syntax consists of a single XML attribute named xml:base.

The deployment of XML Base is through normative reference by new specifications, for example XLink and the XML Infoset. Applications and specifications built upon these new technologies will natively support XML Base. The behavior of xml:base attributes in applications based on specifications that do not have direct or indirect normative reference to XML Base is undefined.

This specification does not attempt to specify which text strings in a document are to be interpreted as URIs. That is the responsibility of each XML vocabulary. The question addressed by this specification is: given a relative URI in an XML document, what base URI is it resolved against?

It is expected that a future RFC for XML Media Types will specify XML Base as the mechanism for establishing base URIs in the media types it defines.

2 Terminology

[Definition: The key words must, must not, required, shall, shall not, should, should not, recommended, may, and optional in this specification are to be interpreted as described in [RFC 2119].]

The terms base URI and relative URI are used in this specification as they are defined in [RFC 3986].

3 xml:base Attribute

The attribute xml:base may be inserted in XML documents to specify a base URI other than the base URI of the document or external entity. The value of this attribute is interpreted as a URI Reference as defined in RFC 2396 [RFC2396], after processing according to Section 3.1 a Legacy Extended IRI (LEIRI) as defined in the W3C Note "Legacy extended IRIs for XML resource identification" [LEIRI] .

In namespace-aware XML processors, the "xml" prefix is bound to the namespace name as described in Namespaces in XML [XML Names]. Note that xml:base can be still used by non-namespace-aware processors.

An example of xml:base in a simple document containing XLinks follows. XLink normatively references XML Base for interpretation of relative URI references in xlink:href attributes.

<?xml version="1.0"?>
<doc xml:base=""
    <title>Virtual Library</title>
    <paragraph>See <link xlink:type="simple" xlink:href="new.xml">what's
    <paragraph>Check out the hot picks of the day!</paragraph>
    <olist xml:base="/hotpicks/">
        <link xlink:type="simple" xlink:href="pick1.xml">Hot Pick #1</link>
        <link xlink:type="simple" xlink:href="pick2.xml">Hot Pick #2</link>
        <link xlink:type="simple" xlink:href="pick3.xml">Hot Pick #3</link>

The URIs in this example resolve to full URIs as follows:


This specification does not give the xml:base attribute any special status as far as XML validity is concerned. In a valid document the attribute must be declared in the DTD, and similar considerations apply to other schema languages.

3.1 URI Reference Encoding and Escaping

The set of characters allowed in xml:base attributes is the same as for XML, namely [Unicode]. However, some Unicode characters are disallowed from URI references, and thus processors must encode and escape these characters to obtain a valid URI reference from the attribute value.

The disallowed characters include all non-ASCII characters, plus the excluded characters listed in Section 2.4 of [RFC2396], except for the number sign (#) and percent sign (%) characters and the square bracket characters re-allowed in [RFC 2732]. Disallowed characters must be escaped as follows:

  1. Each disallowed character is converted to UTF-8 [RFC 2279] as one or more bytes.

  2. Any bytes corresponding to a disallowed character are escaped with the URI escaping mechanism (that is, converted to %HH, where HH is the hexadecimal notation of the byte value).

  3. The original character is replaced by the resulting character sequence.

The value of an xml:base attribute is a Legacy Extended IRI (LEIRI) and may contain characters not allowed in URIs. (However, some characters allowed in LEIRIs are not legal XML characters, and cannot therefore appear in xml:base values.)

In accordance with the principle that percent-encoding must occur as late as possible in the processing chain, applications which provide access to the base URI of an element should calculate and return the value without escaping.

In the example below, the base URI of element e2 should be returned as "é".

<?xml version="1.0"?>
<e1 xml:base="">
  <e2 xml:base="rosé"/>

4 Resolving Relative URIs

RFC 3986 [RFC 3986] provides for base URI information to be embedded within a document. The rules for determining the base URI can be summarized as follows (highest priority to lowest):

  1. The base URI is embedded in the document's content.

  2. The base URI is that of the encapsulating entity (message, document, or none).

  3. The base URI is the URI used to retrieve the entity.

  4. The base URI is defined by the context of the application.


The term "entity" in points #2 and #3 above uses the RFC 3986 meaning of the term. Elsewhere in this document the term "entity" is used in the XML sense.

This document specifies the details of rule #1 for embedding base URI information in the specific case of XML documents.

4.3 Matching URIs with base URIs

The base URI corresponding to a given relative URI appearing in an XML document is determined as follows:


The presence of xml:base attributes might lead to unexpected results in the case where the attribute value is provided, not directly in the XML document entity, but via a default attribute. For instance, such a declaration in an external entity might not be read by software which is based on a non-validating XML processor. Defaulting attributes through an external mechanism such as XML Schema may also lead to unexpected results; even if a validating processor is used by the application, the addition of defaulted attributes subsequent to creation of the infoset can cause xml:base attributes to get out of sync with the [base URI] infoset property. For these reasons, xml:base values should be provided either directly in the XML document instance or via default attributes declared in the internal subset of the DTD.

5 Conformance

An application conforms to XML Base if it calculates base URIs in accordance with the conditions set forth in this specification.

A References

RFC 2119
RFC 2119: Key words for use in RFCs to Indicate Requirement Levels. Internet Engineering Task Force, 1997.
RFC 2279
RFC 2279: UTF-8, a transformation format of ISO 10646. Internet Engineering Task Force, 1998.
RFC 3986
RFC 3986: Uniform Resource Identifier (URI): Generic Syntax. Internet Engineering Task Force, 2005.
Legacy extended IRIs for XML resource identification. Henry S. Thompson, Richard Tobin, and Norman Walsh, editors. World Wide Web Consortium.
RFC 2732
RFC 2732: Format for Literal IPv6 Addresses in URL's. Internet Engineering Task Force, 1999.
The Unicode Standard. The Unicode Consortium.
Extensible Markup Language (XML) 1.0. Tim Bray et al. World Wide Web Consortium.
XML Names
Namespaces in XML 1.0.. Tim Bray et al. World Wide Web Consortium.

B References (Non-Normative)

HTML 4.01
HTML 4.01 Specification. Dave Raggett, Arnaud Le Hors, Ian Jacobs, editors. World Wide Web Consortium, 1999.
XML Linking Language (XLink). Steve DeRose, Eve Maler, David Orchard, and Ben Trafford, editors. World Wide Web Consortium, 2000.
XML Datatypes
XML Schema Part 2: Datatypes. Paul V. Biron, Ashok Malhotra, editors. World Wide Web Consortium Working Draft.
XHTML(TM) 1.0: The Extensible HyperText Markup Language. Steven Pemberton, et al. World Wide Web Consortium, 2000.
XML Infoset
XML Information Set. John Cowan and Richard Tobin, editors. World Wide Web Consortium, 1999.
XML Path Language James Clark and Steven DeRose, editors. World Wide Web Consortium, 1999.
XSL Transformations. James Clark, editor. World Wide Web Consortium, 1999.

C Impacts on Other Standards (Non-Normative)

  • XML 1.0 [XML] uses URI references in the system identifiers for external entities. Since these declarations appear outside of the document element (in an internal subset or external DTD), the scoping rules for xml:base prevent these URIs from being affected by the value of xml:base.

  • The XML Infoset [XML Infoset] defines the base URI property of element information items. The latest Infoset specification supports XML Base for purposes of determining the value of this property. Interfaces, applications, and specifications referencing this infoset property will support XML Base natively.

  • Namespaces in XML [XML Names] uses URI references, which as currently defined should not be resolved relative to the base URI defined by xml:base for the purposes of namespace identification. Higher level processes which dereference namespace URIs are not covered by the namespaces specification and might at their option specify that xml:base is honored for the purposes of fetching resources at those URIs.

  • The XPath [XPath] data model preserves neither base URI information nor the boundaries of external entities and thus is insufficient to support resolution of relative URI references within these entities to be resolved correctly. This includes relative URI references in xml:base attributes.

  • The XSLT [XSLT] extensions to the XPath data model do provide for base URI information to be retained, but defines this information in a way that precludes support for XML Base. Future XSLT versions might want to require support for XML Base.

  • XML Schema Part 2: Datatypes [XML Datatypes] defines a uriReference primitive datatype. The XML Datatypes specification might want to require that applications recognizing this datatype and resolving such URIs be aware of XML Base.

  • The XLink [XLink] specification requires support for XML Base.

  • XHTML [XHTML] uses URI references beyond those expressible in XLink. These URI references might be resolved by an application relative to the base URI defined by XML Base. The XHTML specification might want to describe their level of support for XML Base.

D Changes since the first edition (Non-Normative)

  1. The published errata (see have been incorporated;

  2. The definition of URI reference has been switched from RFC2396 to 3986;

  3. The xml:base attribute has been redescribed as a Legacy Extended IRI, but this does not change its syntax (the December 2006 PER used the term "XML Resource Identifier" which was to be defined in an XLink revision, but that plan has been superseded by the definition of LEIRI in the W3C Note);

  4. Implementations are now encouraged to return base “URIs” without escaping non-URI characters;

  5. The meanings of xml:base="" and xml:base="#frag" have been clarified;

  6. The expected reference to XML Base in the forthcoming XML Media Types RFC (“son of 3023”) has been noted;

  7. It has been clarified that normal validity rules apply to the xml:base attribute;

  8. The out-of-date appendix describing effects on other standards has been removed;

  9. Various minor editorial changes have been made.