note 17596 added to ref.xml

From: Date: Sun, 16 Dec 2001 15:12:32 +0000
Subject: note 17596 added to ref.xml
Groups: php.notes 
Request: Send a blank email to php-notes+get-22923@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> -- http://www.php.net/manual/en/ref.xml.php http://master.php.net/manage/user-notes.php?action=edit+17596 http://master.php.net/manage/user-notes.php?action=delete+17596 http://master.php.net/manage/user-notes.php?action=reject+17596

« previous php.notes (#22923) next »