Voting

: one plus four?
(Example: nine)

The Note You're Voting On

youniforever at naver dot com
20 years ago
<html>
<head>
<title>SAX Demonstration</title>
<META HTTP-EQUIV='Content-type' CONTENT='text/html; charset=euc-kr'>
</head>
<body>
<h1>RSS ??????</h1>

<?php

$file
= "data.xml";

$currentTag = "";
$currentAttribs = "";

function
startElement($parser, $name, $attribs)
{
global
$currentTag, $currentAttribs;
$currentTag = $name;

$currentAttribs = $attribs;
switch (
$name) {

default:
echo(
"<b>&lt$name&gt</b><br>");
break;
}
}

function
endElement($parser, $name)
{
global
$currentTag;
switch (
$name) {
default:
echo(
"<br><b>&lt/$name&gt</b><br><br>");
break;
}
$currentTag = "";
$currentAttribs = "";
}

function
characterData($parser, $data)
{
global
$currentTag;
switch (
$currentTag) {
case
"link":
echo(
"<a href=\"$data\">$data</a>\n");
break;
case
"title":
echo(
"title : $data");
break;
default:
echo(
$data);
break;
}
}

$xmlParser = xml_parser_create();

$caseFold = xml_parser_get_option($xmlParser,
XML_OPTION_CASE_FOLDING);

$targetEncoding = xml_parser_get_option($xmlParser,
XML_OPTION_TARGET_ENCODING);

if (
$caseFold == 1) {
xml_parser_set_option($xmlParser, XML_OPTION_CASE_FOLDING, false);
}

xml_set_element_handler($xmlParser, "startElement", "endElement");
xml_set_character_data_handler($xmlParser, "characterData");

if (!(
$fp = fopen($file, "r"))) {
die(
"Cannot open XML data file: $file");
}

while (
$data = fread($fp, 4096)) {
if (!
xml_parse($xmlParser, $data, feof($fp))) {
die(
sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xmlParser)),
xml_get_current_line_number($xmlParser)));
xml_parser_free($xmlParser);
}
}
xml_parser_free($xmlParser);
?>
</table>
</body>
</html>

<< Back to user notes page

To Top