[nycphp-talk] Trapping Errors with simplexml for Not Well-Formed XML
Daniel Convissor
danielc at analysisandsolutions.com
Sat Feb 10 16:23:19 EST 2007
On Wed, Feb 07, 2007 at 10:21:15AM -0500, =?UTF-8?Q? Emmanuel_M._D=C3=A9carie ?= wrote:
> Adding to this problem, I discovered also that the DOM and simplexml
> extensions can???t use the PHP5 exception handling to trap the errors
> when the XML is not well-formed. Using simplexml or the DOM
> extensions against not well-formed XML, the errors generated by these
> extensions are not trapped and are displayed immediately.
$sxml = @simplexml_load_string($xml);
if ($sxml === false) {
// do what you will about the problem.
}
OR
$php_errormsg = '';
if (!$dom = @DOMDocument::loadXML($xml)) {
// $php_errormsg contains error info.
} elseif (!@$dom->schemaValidate('schema_file.xsd')) {
// $php_errormsg contains error info.
}
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
More information about the talk
mailing list