I am trying to load and xml file (that's created through a web form) into a php page. The directories are created as products get added and an XML written for each product which is to later be called back by the page.
This is the error that I get.
Warning: DOMDocument::load() [domdocument.load]: Entity 'nbsp' not defined in /home/content/41/11699441/html/nc/products/belly-dump/234efg/data.xml, line: 4 in /home/content/41/11699441/html/nc/includes/_xml.php on line 4
Here's the XML loading code:
- $xmlDoc = new DOMDocument();
- $xmlDoc->load('data.xml');
XML File:
<?xml version="1.0"?>
<xml>
<model>
<type>Gravel Box</type>
<titleXML>345FGH - Tridem Clamshell</titleXML>
<features>here are features</features>
<options>here are options</options>
<gallery>my photo gallery directory</gallery>
<info>additional information</info>
</model>
</xml>
PHP Code writing the XML Doc
`$xml = new SimpleXMLElement('');
$model = $xml->addChild('model');
$model->addChild('type', $type);
$model->addChild('titleXML', $titleXML);
$model->addChild('features', $feature);
$model->addChild('options', $option);
$model->addChild('gallery', $gallery);
$model->addChild('info', $info);
$xml->saveXML($target_Path.'data.xml');`
DOMDocument::load()does only process valid XML. You can make use of the$doc->recover = TRUE;switch which will the drop unknown characters (e.g. those with undefined entity names like ). Alternatively if you know that the string is somewhat well-formed you can process entities your own but take care about cdata sections. - hakre entity. This looks pretty wrong in context of your error message. Please double-check and correct as needed. - hakre