note 17596 deleted from ref.xml by jimw

From: Date: Thu, 20 Dec 2001 23:51:57 +0000
Subject: note 17596 deleted from ref.xml by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-23608@lists.php.net to get a copy of this message
<p>I was looking for a simple way to check an xml document for well-formedness. I want to allow content contributors to post their own XML, but I really can't rely on them to not make any mistakes. Ideally, I want my php program to tell them to go back and fix their doc before it is entered in the repository.</p> <p>My solution was to simply attempt to parse the doc, and return an error. If no errors are encountered, we simply continue</p> $file = "mytest.xml"; $xp = xml_parser_create(); if(!($fp = fopen($file, 'r'))) die("Could not open $file for parsing"); while($data = fread($fp, 4096)) { if(!xml_parse($xp, $data, feof($fp))) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xp)), xml_get_current_line_number($xp))); } } // and then on to the code <p>My question - has any one found a better way to check XML?</p>

« previous php.notes (#23608) next »