Skip to content
Permalink
Browse files

Attempt to normalize XML data-streams when comparing for equality.

Used during solution install/reinstall to determine if changes have been
made. Fedora selectively strips newline characters within actual content.
Now we normalize the two data-streams such that all newlines are made spaces
and any preceding/trailing white-space within the document is removed.

For Issue:
https://dgi.ontimenow.com/viewitem.aspx?id=1989&type=features&force_use_number=false
  • Loading branch information...
nigelgbanks committed Jul 22, 2013
1 parent 8496a01 commit 6cc205ec1a390b7eca63a6983778e2c8a9c21caa
Showing with 19 additions and 0 deletions.
  1. +6 −0 includes/solution_packs.inc
  2. +13 −0 xml/strip_newlines_and_whitespace.xsl
@@ -431,12 +431,18 @@ function islandora_check_object_status(AbstractObject $object_definition) {
// we need to replace the info:fedora namespace, as C14N hates it.
// C14N also doesn't normalize whitespace at the end of lines and Fedora
// may add some whitespace on some lines.
$xsl = new DOMDocument();
$xsl->load(drupal_get_path('module', 'islandora') . '/xml/strip_newlines_and_whitespace.xsl');
$xslt = new XSLTProcessor();
$xslt->importStyleSheet($xsl);
$object_definition_dom = new DOMDocument();
$object_definition_dom->preserveWhiteSpace = FALSE;
$object_definition_dom->loadXML(str_replace('info:', 'http://', $ds->content));
$object_definition_dom = $xslt->transformToDoc($object_definition_dom);
$object_actual_dom = new DOMDocument();
$object_actual_dom->preserveWhiteSpace = FALSE;
$object_actual_dom->loadXML(str_replace('info:', 'http://', $existing_object[$ds->id]->content));
$object_actual_dom = $xslt->transformToDoc($object_actual_dom);
// Fedora changes the xml structure so we need to cannonize it.
if ($object_actual_dom->C14N() != $object_definition_dom->C14N()) {
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" media-type="text/xml"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="translate(., '&#xA;', ' ')"/>
</xsl:template>
</xsl:stylesheet>

0 comments on commit 6cc205e

Please sign in to comment.
You can’t perform that action at this time.