#!/usr/bin/env php $line, 'source' => $source, 'message' => $message, 'severity' => 'error', ]; } $document = new \DomDocument('1.0', 'ISO-8859-15'); $checkstyle = new \DOMElement('checkstyle'); $document->appendChild($checkstyle); $checkstyle->appendChild(new \DOMAttr('version', '6.5')); // Write each file to the DOM foreach ($files as $file_name => $error_list) { $file = new \DOMElement('file'); $checkstyle->appendChild($file); $file->appendChild(new \DOMAttr('name', $file_name)); // Write each error to the file foreach ($error_list as $error_map) { $error = new \DOMElement('error'); $file->appendChild($error); // Write each element of the error as an attribute // of the error foreach ($error_map as $key => $value) { $string_value = $escape_html ? htmlspecialchars((string)$value, ENT_NOQUOTES, 'UTF-8') : (string)$value; $error->appendChild( new \DOMAttr($key, $string_value) ); } } } print $document->saveXML();