php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53044 Invalid Nodetype to import
Submitted: 2010-10-11 21:14 UTC Modified: 2011-01-11 19:19 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: bbarnetm at yahoo dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.14 OS: W2K3
Private report: No CVE-ID: None
 [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("&gt","",$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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-11 21:22 UTC] bbarnetm at yahoo dot com
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;
}
 [2010-10-12 05:55 UTC] cataphract@php.net
-Status: Open +Status: Feedback
 [2010-10-12 05:55 UTC] cataphract@php.net
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...
 [2010-10-12 06:55 UTC] bbarnetm at yahoo dot com
-Status: Feedback +Status: Open
 [2010-10-12 06:55 UTC] bbarnetm at yahoo dot com
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?
 [2011-01-11 19:19 UTC] rrichards@php.net
-Status: Open +Status: Bogus
 [2011-01-11 19:19 UTC] rrichards@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 20:01:31 2024 UTC