I have a very long XML composed of articles and I use
$stream = new Stream\File($file, 1024);
$parser = new Parser\StringWalker();
$streamer = new XmlStringStreamer($parser, $stream);
while ($node = $streamer->getNode()) {
$simpleXmlNode = simplexml_load_string($node);
//little debug here
echo (string)$simpleXmlNode->codiceOD;
//
if(isset($simpleXmlNode->gruppo)) {
foreach($simpleXmlNode->gruppo->children() as $child) {
echo ' - ' . ($child);
}
}
echo '<br>';
}
It works very well except for a single line inside an article.
It's Italian language
<datiTecnici><![CDATA[POL<->SCHIENALE. MODULATORE DI SPINTA REGOLABILE. MULTIPOSIZIONATORE DI INCLINAZIONE. RIVESTIMENTO IN PELLE SMERIGLIATA, INTERNO IN SPUGNA HR ALTA DENSITA'. SCOCCA IN FAGGIO MULTISTRATO. BASE IN ALLUMINIO PRESSOFUSO VERNICIATO. BRACCIOLI IN POLIURETANO INTEGRALE CON ANIMA IN ACCIAIO. SEDILE REGOLABILE IN ALTEZZA MEDIANTE PISTONE A GAS (CORSA 10CM). PORTATA MAX 150KG.MISURE: H 117-127CM; L 63CM; P 60CM. (H TERRA<->SEDUTA 44-54CM). 21KG.]]></datiTecnici>
It raises
Warning: simplexml_load_string(): Entity: line 62: parser error : Extra content at the end of the document in /web/htdocs/www.site.net/home/import/iterator.php on line 81
Warning: simplexml_load_string(): in /web/htdocs/www.site.net/home/import/iterator.php on line 81
Warning: simplexml_load_string(): ^ in /web/htdocs/www.site.net/home/import/iterator.php on line 81
Notice: Trying to get property 'codiceOD' of non-object in /web/htdocs/www.site.net/home/import/iterator.php on line 82
Then stops.
I noticed that it has something to do with the length of the content inside CDATA. In fact it works fine if I cut the string a little (don't know how much yet).
What can I do?
I """solved""" it by splitting the big xml into much smaller xmls. I don't know why it works now