Re: [xml-dev] A problem with Base URI and nested XIncludes

From
Tomos Hillman <>
To
XML Developers List <>, Michael Kay <>
Date
2019-08-14T11:39:08Z
ID
<b9226c13-eb50-45ff-a8d1-2b0689bb525a@Spark>
Thread
Re: [xml-dev] A problem with Base URI and nested XIncludes
Xerces seems to be in the wrong, in my somewhat uninformed opinion.

Thanks,
Tom
On 14 Aug 2019, 12:37 +0100, Michael Kay <[email protected]>, wrote:
Further details of this problem can be found here:

https://saxonica.plan.io/issues/4281

We have the following structure:

root.xml:

<root xmlns:xi="http://www.w3.org/2001/XInclude">
    <xi:include href="subfolder/child.xml"/>
</root>

subfolder/child.xml:

<child xmlns:xi="http://www.w3.org/2001/XInclude">
    <xi:include href="otherchild.xml"/>
</child>

subfolder/otherchild.xml:

<otherchild/>
The Xerces parser (both the Apache and JDK versions) presents Saxon with a document like this:

<root xmlns:xi="...">
   <child xml:base="subfolder/child.xml">
      <otherchild xml:base="subfolder/otherchild.xml"/>
   </child>
</root>
and as a result, Saxon reports the base URI of <otherchild> as xxx/subfolder/subfolder/otherchild.xml. My question is: is Xerces getting this wrong, or is Saxon?

The spec for xml:base says (§4.3) The base URI for a URI reference appearing in an xml:base attribute is the base URI of the parent element of the element bearing the xml:base attribute, if one exists within the document entity or external entity, otherwise the base URI of the document entity or external entity containing the element.

It's a bit hard to interpret that, because by the time the elements have acquired an xml:base attribute, they are no longer part of any document or external entity. But I can only see two possible interpretations: (a) otherchild/@xml:base is resolved against the base URI of the <child> element, which gives the result Saxon is showing, and (b) otherchild/@xml:base is resolved against the base URI of the entity that the <otherchild> element originally came from, which gives exactly the same result.

Would anyone argue that the Xerces output is correct?

Michael Kay
Saxonica