Comments (8)
how big is "large data"? megabytes? gigabytes?
from xml.
var_dump(strlen($value)); //1211794
$writer->text($value);
Sometimes, I don't have the errors... it depends perhaps servor memory ?
from xml.
which php version do you use?
from xml.
PHP 5.6
from xml.
This is very interesting. However, I think this bug should be reported at bugs.php.net, as the text
function is just a part of XMLWriter
.
You can report it here: http://bugs.php.net/
If you'd like, please leave a comment here with the php bug id, so we can keep an eye on it.
As a workaround, you might want to try splitting up your $value
variable and call text()
multiple times.
from xml.
How are you writing @cedtaz ? can you include an example PHP snippet?
@evert looking at the write example
$service = new Sabre\Xml\Service();
echo $service->write('foo','bar');
Inside service->write, you use a hardcoded openMemory() on the XMLwriter,
I would suggest adding another method that uses XMLwriter->openURI() to write to a stream.
The same goes for XMLreader. The parse method forces a string in parse()
https://github.com/fruux/sabre-xml/blob/master/lib/Service.php#L109
I added/tested the following method to read from a file or url,
Instead of XMLreader->xml(string), this uses XMLreader->open(uri)
which will stream and accept very large files too.
function parseUri($uri, $contextUri = null, &$rootElementName = null, $encoding = null, $options = 0){
$r = $this->getReader();
$r->contextUri = $contextUri;
$r->open($uri, $encoding, $options);
$result = $r->parse();
$rootElementName = $result['name'];
return $result['value'];
}
(hattip for idea: https://coderwall.com/p/tqggjq/parsing-large-xml-files-using-php )
EDIT: While this may allow to read/write large data sets, memory usage might still be an issue, as the reader continues to read and put the array/structure in memory. An interesting idea might be something like a streamWriter and a streamReader and connect the two with a service to filter from in to out :-)
from xml.
Inside service->write, you use a hardcoded openMemory() on the XMLwriter,
I would suggest adding another method that uses XMLwriter->openURI() to write to a stream.
openURI might help a bit, but it also depends a bit on the situation. Writing to php://memory
will make little difference, to php://temp
will write to disk, which may be good if that's what you're looking for.
But yea you are not prevented from doing this. Just call getWriter()
on the service and initialize the writer yourself. The write()
function is there to address the most common use-case.
Same goes a bit for the reader. I'd definitely be interested in a PR to add parseURI and writeURI though!
EDIT: While this may allow to read/write large data sets, memory usage might still be an issue, as the reader continues to read and put the array/structure in memory. An interesting idea might be something like a streamWriter and a streamReader and connect the two with a service to filter from in to out :-)
Also for these use-case you are definitely not restricted from doing this. If, say, you have a massive atom feed, you could use the reader manually, and only let the xml -> object mapper do its thing for every entry
element in an atom feed. Regardless for reading you need to decide at one point which element you are ultimately 'streaming'. So for an atom feed this could be per-entry.
But yea I'm interested in suggestions otherwise.
from xml.
I'm closing this ticket because it's been a while since the last comment.
If this is indeed still an issue, feel free to comment here so we can continue discussing.
from xml.
Related Issues (20)
- Deserialize unconsistent XML to a normalized Array HOT 5
- [question] parsing child elements which don't have parent namespace HOT 3
- Getting attributes and values from an element not working as expected
- Gcash save money
- Adding a custom DOCTYPE tag
- root and child with the same name
- Is it possible to skip element using deserializer ? HOT 1
- libxml_disable_entity_loader is deprecated as of PHP 8.0 HOT 4
- jaka
- Feature request: changing the default deserializer
- Allow to pass encoding to parse method of Xml/ Service class
- bump min php versions HOT 6
- How to render some element as CDATA? HOT 3
- PHPstan error reported for startElementNs call HOT 1
- how to write macro in epsilon code editor
- Question: Mixing text with tags provides partial result HOT 2
- How save xml content in file ? HOT 1
- Type annotation for Service::write() is not correct
- How can I add an xml-stylesheet tag ?
- PHP message: PHP Fatal error: Type of Sabre\DAV\Xml\Service::$elementMap must be array HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xml.