Comment 1 for bug 627735

Revision history for this message
Hank Bromley (hank-archive) wrote :

Confirmed that we can use Xinclude with php DOMDocument objects. (SimpleXML doesn't support Xinclude, but if we want to work in SimpleXML, we can simply convert to DOMDocument, do the Xinclude, and convert back to SimpleXML.) Wasn't aware of Xinclude until now - thanks, Dan!

The only thing that's slightly tricky is that we need the Xinclude to resolve to multiple nodes (all the second-level elements in the included xml), so that the inherited values don't end up one level deeper in the resulting xml structure than the local ones.

Our scancenter config files look like:

<?xml version="1.0" encoding="UTF-8"?>
<settings>
  <domain>scribe.archive.org</domain>
  <www-domain>archive.org</www-domain>
  ...
</settings>

Let's say we have a shared petabox-sw-config-scancenters.xml file like the above, and we want to overlay it with with some location-specific values. Then we'd have a location-specific file, say petabox-sw-config-sfdowntown.xml, that would look like this:

<?xml version="1.0" encoding="UTF-8"?>
<settings>
  <xi:include href="petabox-sw-config-scancenters.xml#xpointer(/settings/*)"/>
  <timezone-name>PST</timezone-name>
  <timezone-value>-0800</timezone-value>
</settings>

When resolved, the <xi:include> element will be replaced with all the elements immediately below <settings> in petabox-sw-config-scancenters.xml. Without the xpointer, the <settings> element itself would be inserted, burying the intended info one level too deep.

And here's how to make the substitution happen:

$dom = new DOMDocument();
$dom->load("sfdowntown.xml");
$dom->xinclude();

Our DOMDocument now contains the merged values.

We could also take it one step further, and put elements that are in petabox-sw-config-us.xml (the cluster-node config file), as well as the scribe config files, in a base config file that's shared across both the cluster and scancenters. Let's say we call that petabox-sw-config-base.xml. Then we move all the common stuff to there from petabox-sw-config-us.xml and petabox-sw-config-scancenters.xml, replacing it with an xi:include element. The dependencies would look like this:

petabox-sw-config-sfdowntown.xml => petabox-sw-config-scancenter.xml \
                                                                                                                        => petabox-sw-config-base.xml
                                                                            petabox-sw-config-us.xml /