php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47953 Error reading XML string
Submitted: 2009-04-11 23:49 UTC Modified: 2009-04-21 23:44 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: bbarnett at gt dot co dot cr Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.2.9 OS: WXP
Private report: No CVE-ID: None
 [2009-04-11 23:49 UTC] bbarnett at gt dot co dot cr
Description:
------------
I'm receiving and error when I try to read and XML string. The error is: Premature end of data in tag FechaPago line 9 Line: 9

Reproduce code:
---------------
$xml2= simplexml_load_string(utf8_decode(trim($reg[0])));

Expected result:
----------------
An XML object

Actual result:
--------------
An Error.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-12 00:03 UTC] bbarnett at gt dot co dot cr
This is an example of the XML string that I'm trying to read
<X_A_PagoGen>
  <Banco>2</Banco>
  <Localizacion>8203261610</Localizacion>
  <NotaCredito>000000009770</NotaCredito>
  <Correlativo>80782584</Correlativo>
  <Self>9</Self>
  <Monto>0000011930</Monto>
  <Agencia>1400</Agencia>
  <FechaPago>20090216</FechaPago>
  <FechaCaja>20090217</FechaCaja>
</X_A_PagoGen>
 [2009-04-12 00:07 UTC] bbarnett at gt dot co dot cr
This is a part of the code that I'm using:
<?
$consulta="select trama from gestiones where consecutivo=".trim($_REQUEST['consecutivo']);
$buffconsulta = mssql_query($consulta,$conn);
$reg = mssql_fetch_row($buffconsulta);
		
// Procesa el XML enviado
$xml2= simplexml_load_string(utf8_decode(trim($reg[0])));
if (!$xml2){
	print wordwrap($reg[0], 30, "<br>",1);
} 
?>
 [2009-04-15 11:55 UTC] rrichards@php.net
There's bad data somewhere in your XML. No idea what encoding the data 
is, but converting it to ISO-8859-1 without an XML declaration using 
that encoding is a sure path to disaster.
 [2009-04-15 15:40 UTC] bbarnett at gt dot co dot cr
I try without the utf8_decode, but I'm receiving the same result.

$xml2= simplexml_load_string(trim($reg[0]));

Can you help me?
 [2009-04-15 15:58 UTC] bbarnett at gt dot co dot cr
I'm adding the XML head to the string like this

<?xml version="1.0" encoding="UTF-8"?>
<X_A_PagoGen>
  <Banco>2</Banco>
  <Localizacion>7901160655</Localizacion>
  <NotaCredito>000000009726</NotaCredito>
  <Correlativo>79613565</Correlativo>
  <Self>5</Self>
  <Monto>0000010605</Monto>
  <Agencia>1400</Agencia>
  <FechaPago>20090102</FechaPago>
  <FechaCaja>20090105</FechaCaja>
</X_A_PagoGen>
But I'm receiving the same result. 

In the next case the function read the XML without problem

<X_C_Localizacion>
  <Localizacion>7901160655</Localizacion>
</X_C_Localizacion>
 [2009-04-15 17:10 UTC] rrichards@php.net
Not a bug. You have bad data - most likely an invisible char.
 [2009-04-15 17:46 UTC] bbarnett at gt dot co dot cr
Excuse too many questions, but I need to resolve this.

if is this true, why if is the same provider for this string in one case works and in the other none???

Thank's for your help :)
 [2009-04-21 23:44 UTC] bbarnett at gt dot co dot cr
I don't know why this issue was clasified as bogus, because its a PHP error.

I wrote again the code to generate the XML that is read it in other company without problem, but when I try to read it, I'm receiving the same error reported before.

There are not hidden characters that I put like Richards wrote before.

Please help me with this problem

// Crea objeto XML
	$doc = new DOMDocument('1.0'); $doc->formatOutput = true;
	$root = $doc->createElement('X_A_PagoGen'); 
	$root = $doc->appendChild($root);
	
	$title = $doc->createElement('Banco'); 
	$title = $root->appendChild($title);
	$text = $doc->createTextNode(trim($codigobanco)); 
	$text = $title->appendChild($text);
	
	$title = $doc->createElement('Localizacion'); 
	$title = $root->appendChild($title);
	$text = $doc->createTextNode(trim($localizacion)); 
	$text = $title->appendChild($text);
	
	$title = $doc->createElement('NotaCredito'); 
	$title = $root->appendChild($title);
	$text = $doc->createTextNode(llenacampo(trim($remesa),12,'0','derecha')); 
	$text = $title->appendChild($text);
	
	$title = $doc->createElement('Correlativo'); 
	$title = $root->appendChild($title);
	$text = $doc->createTextNode(trim($factura)); 
	$text = $title->appendChild($text);
	
	$title = $doc->createElement('Self'); 
	$title = $root->appendChild($title);
	$text = $doc->createTextNode(trim($self)); 
	$text = $title->appendChild($text);
	
	$title = $doc->createElement('Monto'); 
	$title = $root->appendChild($title);
	$text = $doc->createTextNode(llenacampo(trim($monto),10,'0','derecha')); 
	$text = $title->appendChild($text);
	
	$title = $doc->createElement('Agencia'); 
	$title = $root->appendChild($title);
	$text = $doc->createTextNode(trim($recaudadorCNFL)); 
	$text = $title->appendChild($text);	
	
	$title = $doc->createElement('FechaPago'); 
	$title = $root->appendChild($title);
	$text = $doc->createTextNode(trim(fecha1())); 
	$text = $title->appendChild($text);	
	
	$title = $doc->createElement('FechaCaja'); 
	$title = $root->appendChild($title);
	$text = $doc->createTextNode(trim($deposito)); 
	$text = $title->appendChild($text);	
	
	$tramaxml=$doc->saveXML();
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 10:01:28 2024 UTC