J
Jos van Uden
Can somebody explain why the following file
has the wrong output:
<?xml version="1.0" encoding="iso-8859-1"?>
<test>
<elem>‘bla bla bla’</elem>
</test>
Expected: ‘bla bla bla’
output: ?bla bla bla?
It's not caused by the browser, but
by the (expat) xml parser.
Thanks.
test script:
<?php
$file = "test.xml";
$testdata;
$tagname;
function startElement($parser, $name, $attrs) {
global $tagname;
$tagname = $name;
}
function endElement($parser, $name) {
}
function characterData(&$parser, $data) {
global $testdata, $tagname;
if(trim($data) != "") {
switch($tagname) {
case 'ELEM' :
$testdata .= $data;
break;
}
}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, 'characterData');
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
print "output : " .$testdata;
?>
has the wrong output:
<?xml version="1.0" encoding="iso-8859-1"?>
<test>
<elem>‘bla bla bla’</elem>
</test>
Expected: ‘bla bla bla’
output: ?bla bla bla?
It's not caused by the browser, but
by the (expat) xml parser.
Thanks.
test script:
<?php
$file = "test.xml";
$testdata;
$tagname;
function startElement($parser, $name, $attrs) {
global $tagname;
$tagname = $name;
}
function endElement($parser, $name) {
}
function characterData(&$parser, $data) {
global $testdata, $tagname;
if(trim($data) != "") {
switch($tagname) {
case 'ELEM' :
$testdata .= $data;
break;
}
}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, 'characterData');
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
print "output : " .$testdata;
?>