Skip to content

Commit

Permalink
Fix xml error on export with non-escaped '&'
Browse files Browse the repository at this point in the history
git-svn-id: https://xerteonlinetoolkits.googlecode.com/svn/trunk@451 912cdd6b-5c7d-d5a7-a2ba-d0f0cdb91641
  • Loading branch information
torinfo committed Oct 12, 2012
1 parent 3a43818 commit 6494bc5
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions website_code/php/xmlInspector.php
Expand Up @@ -20,10 +20,45 @@ private function addModel($model)
array_push($this->models, $model);
}

private function fixXmlFile($name)
{
$xmlcontents = file_get_contents($name);
//_debug("1. " . $xmlcontents);
// Ok replace known escape sequences to something without an '&'
$xmlcontents = str_replace('<', '%%%lt;', $xmlcontents);
$xmlcontents = str_replace('>', '%%%gt;', $xmlcontents);
$xmlcontents = str_replace('"', '%%%quot;', $xmlcontents);
$xmlcontents = str_replace(' ', '%%%nbsp;', $xmlcontents);
$xmlcontents = str_replace('&', '%%%amp;', $xmlcontents);

//_debug("2. " . $xmlcontents);
// replace & with &
$xmlcontents = str_replace('&', '&', $xmlcontents);

// replace known escape sequences back
$xmlcontents = str_replace('%%%lt;', '<', $xmlcontents);
$xmlcontents = str_replace('%%%gt;', '>', $xmlcontents);
$xmlcontents = str_replace('%%%quot;', '"', $xmlcontents);
$xmlcontents = str_replace('%%%nbsp;', ' ', $xmlcontents);
$xmlcontents = str_replace('%%%amp;', '&', $xmlcontents);

//_debug("3. ". $xmlcontents);

$res = file_put_contents($name, $xmlcontents);
//_debug("4. " . $res);
}

public function loadTemplateXML($name)
{
$this->fname = $name;
libxml_use_internal_errors(true);
$this->xml = simplexml_load_file($name);
if (!$this->xml)
{
_debug("Error detected in XML, try to fix...");
$this->fixXmlFile($name);
$this->xml = simplexml_load_file($name);
}
$this->models = array();
$nodes = $this->xml->xpath('/*/*');
foreach ($nodes as $node)
Expand Down

0 comments on commit 6494bc5

Please sign in to comment.