In my website I put out a lot of internal tracing information for development testing. The content of the trace is formatted for HTML which is fine most of the time, but in order to support AJAX sometimes I want to include that trace data in an XML document. Occasionally XML objects that there are unmatched tags, but it only reports the location in the document where the end tag is missing. These trace documents are typically 10,000 lines long and are generated by code all over the system, so debugging the debugging information is non-trivial. In my current problem the XML parse reported that I was missing a closing </p>.
So I added:
libxml_use_internal_errors(true);
$doc = simplexml_load_string($warn);
$xml = explode("\n", $warn);
if (!$doc) {
$errors = libxml_get_errors();
foreach ($errors as $error) {
echo display_xml_error($error, $xml);
}
libxml_clear_errors();
}
to the spot where the trace data is sent to stdout. Now I get:
<p>User::__construct(Array
-^
Fatal Error 5: Extra content at the end of the document
Line: 2
Column: 1
--------------------------------------------
<div id='debugTrace' class='warning'>
<p>connection established to database server 'mysql:...'.</p>
<p>User::__construct(Array
(
[username] => jcobban
)
)</p>
<p>SELECT * FROM Users WHERE UserName='jcobban'</p><p class='label'>User Record constructed:</p>
... for 9997 more lines
The <div> is used to enclose all of the trace output with the class styling the output in dark yellow.
Both the XML parser in Firefox and PHP simple XML agree that there is a missing closing </p>, but I see the closing tag in the resulting document, as displayed when I ask XML to display the page source. The line of code that emits the apparently offending line is:
$warn .= "<p>User::__construct(" . print_r($parms, true) .
")</p>\n";
So what am I doing wrong?