note 29550 modified in ref.xml by danbrown
| From: | danbrown@php.net | Date: | Wed, 03 Mar 2010 18:45:41 +0000 |
| Subject: | note 29550 modified in ref.xml by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-166603@lists.php.net to get a copy of this message | ||
My previous XML post (software at serv-a-com dot com/22-Jan-2003 03:08) resulted in some of the
visitors e-mailg me on the carriage return stripping issue with questions. I'll try to make the
following mumble as brief and easy to understand as possible.
1. Overview of the 4096 fragmentation issue
As you know the following freads the file 4096 bytes at a time (that is 4KB) this is perhaps ok for
testing expat and figuring out how things work, but it it rather dangerous in the production
environment. Data may not be fully understandable due to fread fragmentation and improperly
formatted due to numerous sources(formats) of data contained within (i.e. end of line delimited
CDATA).
<?php
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
// ...
}
}
?>
Sometimes to save time one may want to load it all up into a one big variable and leave all the
worries to expat. I think anything under 500 KB is ok (as long as nobody knows about it). Some may
argue that larger variables are acceptable or even necessary because of the magic that take place
while parsing using xml_parse. Our XML parser(expat) works and can be successfully implemented only
when we know what type of XML data we are dealing with, it's average size and structure of
general layout and data contained within tags. For example if the tags are followed by a line
delimiter like a new line we can read it with fgets in and with minimal effort make sure that no
data will be sent to the function that does not end with a end tag. But this require a fair
knowledge of the file's preference for storing XML data and tags (and a bit of code between
reading data and xml_parse'ing it).
--was--
My previous XML post (software at serv-a-com dot com/22-Jan-2003 03:08) resulted in some of the
visitors e-mailg me on the carriage return stripping issue with questions. I'll try to make the
following mumble as brief and easy to understand as possible.
1. Overview of the 4096 fragmentation issue
As you know the following freads the file 4096 bytes at a time (that is 4KB) this is perhaps ok for
testing expat and figuring out how things work, but it it rather dangerous in the production
environment. Data may not be fully understandable due to fread fragmentation and improperly
formatted due to numerous sources(formats) of data contained within (i.e. end of line delimited
CDATA).
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
Sometimes to save time one may want to load it all up into a one big variable and leave all the
worries to expat. I think anything under 500 KB is ok (as long as nobody knows about it). Some may
argue that larger variables are acceptable or even necessary because of the magic that take place
while parsing using xml_parse. Our XML parser(expat) works and can be successfully implemented only
when we know what type of XML data we are dealing with, it's average size and structure of
general layout and data contained within tags. For example if the tags are followed by a line
delimiter like a new line we can read it with fgets in and with minimal effort make sure that no
data will be sent to the function that does not end with a end tag. But this require a fair
knowledge of the file's preference for storing XML data and tags (and a bit of code between
reading data and xml_parse'ing it).
http://php.net/manual/en/ref.xml.php