|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-10-11 21:14 UTC] bbarnetm at yahoo dot com
Description:
------------
While I'm trying to import an extensive xml, I'm recieving the same error while I
try to transale to simple xml.
Test script:
---------------
libxml_use_internal_errors(true);
$xmlestilos=ereg_replace(chr(160),"",(trim($reg[0])));
$xmlestilos=ereg_replace('"',"",$xmlestilos);
$xmlestilos=ereg_replace(",",".",$xmlestilos);
$xmlestilos=ereg_replace("&","",$xmlestilos);
$xmlestilos=ereg_replace(">","",$xmlestilos);
$xmlestilos=ereg_replace("}","",$xmlestilos);
$xmlestilos=ereg_replace("#","",$xmlestilos);
$xmlestilos=ereg_replace("`","",$xmlestilos);
$xmlestilos=ereg_replace(";","",$xmlestilos);
$xmlestilos=ereg_replace("[\\|]+","",$xmlestilos);
$xmlestilos=ereg_replace("[\\]+","/",$xmlestilos);
$xmlestilos=ereg_replace("¦","",($xmlestilos));
$xmlestilos=ereg_replace("º","",($xmlestilos));
$xmlestilos=ereg_replace("´","",($xmlestilos));
$xmlestilos=ereg_replace("¨","",($xmlestilos));
$xmlestilos=ereg_replace("[\\?]+","",($xmlestilos));
$xmlestilos=ereg_replace("[\\¿]+","",($xmlestilos));
$xmlestilos=acentos($xmlestilos);
$xmlestilos=stripslashes($xmlestilos);
$xmlestilos=utf8_decode($xmlestilos);
$dom = new domDocument;
$dom->loadXML($xmlestilos);
if (!$dom) {
//Escribe la respuesta en un archivo
$formato1 = '%d%m%Y'; $hoyes = strftime($formato1); $archivolog="estilos_".$hoyes.".log";
if (file_exists($archivolog)){unlink($archivolog);}
$fp = fopen ($archivolog, "a");
//fwrite ($fp, trim($reg[0]). PHP_EOL);
fwrite ($fp, trim($xmlestilos). PHP_EOL);
fclose($fp);
print 'MSG-18: SE DETECTO UNA RESPUESTA INVALIDA DEL INS'; die();
}
$xml = simplexml_import_dom($dom);
Expected result:
----------------
The xml imported in a simple xml object
Actual result:
--------------
Warning: simplexml_import_dom() [function.simplexml-import-dom]: Invalid Nodetype
to import in E:\SITIOS\PayWebCoopemex\INS\ins-405.srv.php on line 149
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 09:00:01 2025 UTC |
function acentos($valor){ //Le elimina los acentos al string recibido $registro=$valor; $registro=ereg_replace("á","a",($registro)); $registro=ereg_replace("é","e",($registro)); $registro=ereg_replace("í","i",($registro)); $registro=ereg_replace("ó","o",($registro)); $registro=ereg_replace("ú","u",($registro)); $registro=ereg_replace("Á","A",($registro)); $registro=ereg_replace("É","E",($registro)); $registro=ereg_replace("Í","I",($registro)); $registro=ereg_replace("Ó","O",($registro)); $registro=ereg_replace("Ú","U",($registro)); $registro=ereg_replace("ñ","n",($registro)); $registro=ereg_replace("Ñ","N",($registro)); return $registro; }I'd guess the DOMDocument object is empty because the call to loadXML() failed. You should do if (!$dom->loadXML(...)) { //error loading XML. Call libxml_get_errors() to get details } not if (!$dom) { Please confirm this is the case. In any case, the error message could be better...I modified my script following your tip I founded enough information for incluye aditional lines: $xmlestilos=ereg_replace("[\\Ð]+","",($xmlestilos)); $xmlestilos=ereg_replace("[\\ð]+","",($xmlestilos)); The script was modified: if (!($dom->loadXML($xmlestilos))){ $errors = libxml_get_errors(); foreach ($errors as $error) { echo display_xml_error($error, $xmlestilos); } libxml_clear_errors(); } Thank very much for your tip. Let me know if in a future versions you will increment the power of xml functions?