Doc #54937 [Opn->Bgs]: SIMPLEXML fails to parse correctly

From: Date: Fri, 27 May 2011 13:24:01 +0000
Subject: Doc #54937 [Opn->Bgs]: SIMPLEXML fails to parse correctly
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-6665@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=54937&edit=1 ID: 54937 Updated by: salathe@php.net Reported by: glen2023 at gmail dot com Summary: SIMPLEXML fails to parse correctly -Status: Open +Status: Bogus Type: Documentation Problem Package: Class/Object related Operating System: linux ubuntu 8.10 PHP Version: 5.2.17 Block user comment: N Private report: N New Comment: The attribute is not lost forever, it is just that print_r() does not display it. Attributes are accessible via the array-style syntax [1] or attributes() method [2]. [1] http://php.net/simplexml.examples-basic [2] http://php.net/simplexmlelement.attributes Previous Comments: ------------------------------------------------------------------------ [2011-05-27 08:25:15] glen2023 at gmail dot com Description: ------------ --- From manual page: http://www.php.net/book.simplexml --- As far as I know, object nodes can only have characters (a-zA-Z0-9_). I think problem is created when SIMPLEXML uses @ in @attributes nodes. It works most of the time, but a node attribute is lost for certain xml data like I demonstrated below. Test script: --------------- $xml =<<<ENDOF <root> <zakara ee="rr1"> <xx>aa1</xx> <xx plop="huhuD">aa4</xx> </zakara> </root> ENDOF; $obj=simplexml_load_string($xml,'SimpleXMLElement', LIBXML_NOCDATA|LIBXML_NOBLANKS|LIBXML_NOERROR|LIBXML_NOWARNING); if (!$obj) die(); print_r($obj); [plop] => huhuD dissapears. Expected result: ---------------- Array ( [zakara] => Array ( [@attributes] => Array ( [ee] => rr1 ) [xx] => Array ( [0] => aa1 [1] => ( [@attributes] => Array ( [plop] => huhuD ) [0]=> aa4 ) ) ) ) Actual result: -------------- Array ( [zakara] => Array ( [@attributes] => Array ( [ee] => rr1 ) [xx] => Array ( [0] => aa1 [1] => aa4 ) ) ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54937&edit=1

« previous php.doc.bugs (#6665) next »