php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55279 SimpleXml removes line breaks
Submitted: 2011-07-25 06:17 UTC Modified: 2012-09-20 06:51 UTC
Votes:3
Avg. Score:3.7 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: mathieu at webberig dot be Assigned: rrichards (profile)
Status: Not a bug Package: SimpleXML related
PHP Version: 5.3.6 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mathieu at webberig dot be
New email:
PHP Version: OS:

 

 [2011-07-25 06:17 UTC] mathieu at webberig dot be
Description:
------------
SimpleXML seems to ignore/remove line breaks (\n) in the attributes. Line breaks 
inside an attribute are valid XML, but they're lost when you use SimpleXML to read 
the XML data.

I encountered this problem when reading XML data provided by the Google Webmaster 
Tools API

Test script:
---------------
XML:
<?xml version="1.0"?>
<feed><entry description="this is the first line
here's a second line
and another!" /></feed>

PHP:
$xml = simplexml_load_string($xmldata);
foreach ($xml->entry as $entry)
{
$attributes = $entry->attributes();
print_r($attributes);
}

Expected result:
----------------
Keep the line breaks from the attribute values after reading the string.
$attributes['description'] == "this is the first line
here's a second line
and another!";

Actual result:
--------------
The string no longer contains line breaks:
$attributes['description'] == "this is the first line here's a second line and 
another!";

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-25 06:27 UTC] pajoye@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: rrichards
 [2011-07-25 06:27 UTC] pajoye@php.net
As http://www.w3.org/TR/REC-xml/#NT-AttValue says than new lines are valid in 
attribute values, it seems that almost no parser returns them.

This is certainly a problem in libxml itself as simplexml does not transform the 
values returned by libxml.

Assigne to Rob so he can check with the libxml devs, whether we like to change 
that or not :)
 [2012-09-20 06:51 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

Attribute values are normalized: http://www.w3.org/TR/REC-xml/#AVNormalize
 [2012-09-20 06:51 UTC] rrichards@php.net
-Status: Assigned +Status: Not a bug
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Nov 27 15:05:53 2022 UTC