I found a solution, but it is a bit hackish, so I'm still open for better suggestions.
Put <pre>
around the xml you want to validate (this instructs Tidy not to change the whitespace), then repair the xml with output-html set to true, then remove the <pre>
and \n
newlines.
Example:
$config = array(
'indent' => false,
'indent-attributes' => false,
'output-html' => true,
'input-xml' => true,
'wrap' => 0,
'vertical-space' => false,
'new-inline-tags' => 'context,abr,stress',
'new-blocklevel-tags' => 'def,ex,examples'
);
$tidy = new tidy();
$inputXml = "<pre>" . $inputXml . "</pre>";
$validXml = $tidy->repairString($inputXml, $config, 'utf8');
$cleanXml = str_replace("\n", "", $validXml);
$cleanXml = substr($cleanXml, strlen("<pre>"), strlen($cleanXml));
$cleanXml = substr($cleanXml, 0, strlen($cleanXml)-strlen("</pre>"));