XML technologies / XML / XML in a Nutshell / XInclude / Content negotiation
(Excerpt from "XML in a Nutshell" by Elliotte Rusty Harold & W. Scott Means)
HTTP clients and servers support various accept headers indicating the content a client can receive. For example, this browser request prefers French but also accepts English. It supports HTML, plain text and JPEG images, can decode gzip-compressed data, and recognizes the ASCII and Latin-1character sets as well as the UTF-8 encoding of the Unicode character set.
GET /index.html HTTP/1.1 User-Agent: Mozilla/4.6 [en] (WinNT; I) Host: www.cafeaulait.org Accept: text/html, text/plain, image/jpeg Accept-Encoding: gzip Accept-Language: fr, en Accept-Charset: us-ascii, iso-8859-1,utf-8 Connection: close If-Modified-Since: Sun, 31 Oct 1999 19:22:07 GMT
The server uses these headers to choose which resource version to send. The same URL can provide different content depending on the headers. Browsers usually control this through user preferences. However, XInclude lets you control two of these headers through attributes: accept and accept-language. Each xi:include element can have an accept and/or accept-language attribute. Their values should be valid for the corresponding HTTP header fields. If either or both attributes are present, the XInclude processor adds those headers to its HTTP request. For example, this xi:include element requests inclusion of the French HTML version of Google’s home page:
<xi:include href="http://www.google.com" parse="text" accept-language="fr" accept="text/html"/>This xi:include element requests the English XML version of Google’s home page:
<xi:include href="http://www.google.com" accept-language="en" accept="application/xml"/> accept and accept-language can both be used in any combination with parse="xml" and parse="text".
Of course, not every URL offers the requested language and content type. Most servers always return the same page in the same language, regardless of the accept headers. Where a server offers translations and formats of the same resource, these attributes let you state your preference.
Copyright © 2005 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from the book "XML in a Nutshell" is subject to the same conditions as the printed edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de
back to top