You are here: Strange issue with xml_parse_into_struct « PHP « IT news, forums, messages
Strange issue with xml_parse_into_struct

Posted by Mark Evans on 09/20/05 12:45

Hi All

I am having an issue when trying to parse an xml document with namespaces.

The XML data I am trying to parse looks like the following

<my:object name="__root">%3Chtml%3E%0A%3Chead%3E%0A%3Ctitle%3E<my:variable
name='Test'/>%3C%2Ftitle%3E%0A%0A%3C%2Fhead%3E%0A%3Cbody%3E%0A%0A%3C%2Fbody%3E%0A%3C%2Fhtml%3E%0A</my:object>

A small script to reproduce the problem I am having is as follows (note:
This isnt pretty I know ;-))

<?php
$sFile = "data.xml";
$xml_parser = xml_parser_create_ns();

if (!($pFile = fopen($sFile, "r")))
{
die("could not open XML input");
}

$sData = fread($pFile, filesize($sFile));
fclose($pFile);

if (!xml_parse_into_struct($xml_parser, $sData, $aVals, $aIndex))
{
$nErrorCode = xml_get_error_code($xml_parser);
$sError = xml_error_string($nErrorCode);
$sErrorMessage = 'XML Parser Error: Error Code: ' . $nErrorCode . ' Error
String: ' . $sError . ' Line Number: ' .
xml_get_current_line_number($xml_parser);
trigger_error($sErrorMessage, E_USER_WARNING);
}
?>

This script works perfectly on all versions of PHP on Windows.. however
as soon as I test this on a FreeBSD box running 4.4.0 or a CentOS box
running 4.3.9 I get the same error

Warning: XML Parser Error: Error Code: 27 Error String: unbound prefix
Line Number: 1 in /usr/local/www/data-dist/xml/test.php on line 18

If I change

$xml_parser = xml_parser_create_ns();

to

$xml_parser = xml_parser_create();

It does work on both platforms.

The question is (finally ;-)) can anyone see anything wrong with what I
am trying to do? Is there an issue in xml_parse_into_struct when used
with xml_parser_create_ns on non-windows platforms (the latter I dobut
as I have searched the php bugs section and havent found anything
relating to this).

TIA

Mark

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация