xp-framework/rfc — Issue #179: Add stream support to XML parser
Author: thekid
Created: 2011-10-17 16:03:23+00:00
State: closed
Labels: framework, implemented

Scope of Change
====
The xml.parser.XMLParser class will support parsing streams.

Rationale
====
Not having to load file contents into memory completely before being
ablt to parse them.

Functionality
====
The `xml.parser.XMLParser::parse()` method will be changed to accept
either strings (as it does now) or `xml.parser.InputSource` objects.

Current API
----
This shows that before parsing XML, it needs to be loaded into a string.
This may be best for small files but will create memory problems when
the file size increases:

```php
parse($xml);
?>
```

New API
----
Here, the parsing is done while loading the file from the stream. Also,
because FileInputStream can easily be substituted for any other input
stream, it's more flexible.

```php
parse(new FileInputSource(new File('example.xml')));
?>
```

More examples:

```php
parse(new StringInputSource($xml));
$parser->parse(new FileInputSource(new File('example.xml')));
$parser->parse(new StreamInputSource(new FileInputStream(new File('example.xml'))));
?>
```

Security considerations
====
None.

Speed impact
====
Faster for the stream case.

Dependencies
====
None, the old behaviour of passing a string to `parse()` will be
kept.

Related documents
====
http://xp-framework.net/rfc/contrib/rfc0179.diff