Search code examples
xinclude

can XInclude be used on stream input?


I would like a portable solution to creating a multiply nested XML document using XInclude. I am using <xi:include href="foo.xml"> elements and taking the input from a stream. So far this fails (I am using XOM which has its own XIncluder) which reports it cannot find the base URL for the href. I am wondering if this is a general problem (see XercesDOMParser and XIncludes ). If so are there general workarounds?


Solution

  • A relative URI like foo.xml is useless without the context of a base URI with which to work out that e.g. if the base URI is http://example.net/bar/baz.xml then the absolute URI of the resource is http://example.net/bar/foo.xml.

    This base URI can come from:

    1. The URI that the XML in question came from (clearly not applicable to a stream alone).
    2. A URI passed to a parser by mechanisms specific to it.
    3. xml:base
    4. Means specific to a given XML application (not advisable, but sometimes necessary for compatibility with other formats, e.g. the <base /> element in XHTML duplicates xml:base unnecessarily and with less flexibility, but is required for compatibility with HTML4.01 and earlier).