Parsing the phpdocs using PHP.
| From: | David Medinets | Date: | Sat, 03 Jul 1999 18:20:39 +0000 |
| Subject: | Parsing the phpdocs using PHP. | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-8054@lists.php.net to get a copy of this message | ||
Hi. I order to better understand the XML parsing functions of PHP. I
seemed like a good idea to parse the documentation itself. Using the
code shown below I recieve many errors. Some of them are shown below.
Shoul the php documentatin be able to be parsed? I want to believe
the answer is yes.
Am I doing something wrong?
david
REPRESENTATIVE ERRORS
err=undefined entity at 197
url="&url.unicode;">Unicode</ulink> character set through
err=duplicate attribute at 198
different <glossterm>character encoding</glossterm>s. There
err=duplicate attribute at 199
are two types of character encodings, <glossterm>source
err=duplicate attribute at 200
encoding</glossterm> and <glossterm>target
CODE LISTING
$depth = array();
function startElement($parser, $name, $attrs) {
global $depth;
for ($i = 0; $i < $depth[$parser]; $i++) {
print " ";
}
print "$name<br>";
$depth[$parser]++;
}
function endElement($parser, $name) {
global $depth;
$depth[$parser]--;
}
$file_xml = "/usr/storage/cvs/phpdoc/functions/xml.sgml";
$ary_lines = file($file_xml);
echo "<b>XML Parsing</b><br><br>";
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
$num_lines = count($ary_lines) - 1;
while (list($key, $value) = each($ary_lines)) {
$bln_end_of_array = $num_lines == $key;
if (! xml_parse($xml_parser, $value, $bln_end_of_array)) {
$err_string = xml_error_string(xml_get_error_code($xml_parser));
$err_line = xml_get_current_line_number($xml_parser);
echo "err=$err_string at $err_line<br>";
echo "<ul><pre>";
echo htmlspecialchars($value);
echo "</pre></ul>";
}
}
xml_parser_free($xml_parser);
?>