Monday, June 12, 2006

XInclude at last gets rid of xml:base

I had heard the rumor already, but by checking the XInclude errata it turns out this was right: XInclude now officially allows implementations to provide an option to disable xml:base fixup, in other words not to produce or update xml:base attributes in the result.

This was a long-awaited feature. Adding xml:base attributes can cause issues such as broken schema validation (you may have to modify your schema to handle those extra xml:base attributes, or pre-process your document before validating it) or undesired URL resolution in certain cases.

For example, with the OPS XForms engine, let's assume you want to externalize an XForms model, and include it into your XHTML page as follows:

    <xi:include href="oxf:/my-app/my-xforms-model.xml"/>

The result of the inclusion, by default, looks like this:

    <xforms:model xml:base="oxf:/my-app/my-xforms-model.xml">
        <xforms:submission action="services/save" method="post"/>

Now what you intended was that the relative "services/save" URL would be relative to the base URL of your XHTML page. If you loaded your page from "", you would submit to "". But because xml:base is inserted, you actually save to "oxf:/my-app/services/save", which does not make any sense. And this is messed up just because you decided to externalize your XForms model for convenience.

So the OPS XInclude processor now includes an extension attribute, xxi:omit-xml-base, which you can place on xi:include elements to indicate that you don't want the inclusion to produce or update xml:base attributes. The example above becomes:

    <xi:include href="oxf:/my-app/my-xforms-model.xml" xxi:omit-xml-base="true"/>

This way, all is well and your URL resolution works as expected!

No comments:

Post a Comment