I've got a bunch of XML file which I'm loading in to my script using XMLReader, creating DOM object and then converting to Simplexml.
Problem is one of the XML file uses CDATA which SIMPLEXML ignores and normally using SIMPLEXML_LOAD_FILE I'd add the LIBXML_NOCDATA parameter but as I'm using simplexml_import_dom I can't figure out how to ignore the CDATA in the sceanrio below.
Any ideas please?
Many thanks Brett
$file = 'test.xml';
$reader = new XMLReader();
$reader->open($file);
while ($reader->read())
{
// are we in a product?
if ($reader->nodeType == XMLReader::ELEMENT &&
strtolower($reader->localName) == 'product')
{
if (!$node = $reader->expand()) {
//do nothing
}
else {
// expand the node into a DOMNode
// Convert to SimpleXML via DOM, messy but SimpleXML is soo much nicer.
$dom = new DomDocument();
$dom->appendChild($dom->importNode($node, true));
$products = simplexml_import_dom($dom);
// do whatever we want to do with the product data
}