When I try to Import xml file, it returns an error:
xmlParseCharRef: invalid xmlChar value
4"because of$amp;in xml<STOCKGROUP >NAME="ABC & Glass" RESERVEDNAME="">
Here is code I'm using to read xml file data
function add_product_type()
{
print_r($_FILES);
if (isset($_FILES['product_type_file']) && ($_FILES['product_type_file']['error'] == UPLOAD_ERR_OK)) {
$use_errors = libxml_use_internal_errors(true);
$response = simplexml_load_file($_FILES['product_type_file']['tmp_name']);
print_r($response);
foreach($response->BODY->IMPORTDATA as $key => $value) {
foreach($value->REQUESTDATA->TALLYMESSAGE as $key => $values) {
if (strstr("&", $values->STOCKGROUP->attributes())) {
$name = str_replace("&", "&", $values->STOCKGROUP->attributes());
}
else {
$name = $values->STOCKGROUP->attributes();
}
echo $name . ",";
}
}
if ($response == false) {
echo "Failed loading XML\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
}
}
}