note 108029 added to simplexmlelement.attributes

From: Date: Fri, 23 Mar 2012 10:16:07 +0000
Subject: note 108029 added to simplexmlelement.attributes
Groups: php.notes 
Request: Send a blank email to php-notes+get-186786@lists.php.net to get a copy of this message
Note that you must provide the namespace if you want to access an attribute of a non-default namespace: Consider the following example: <?php $xml = <<<XML <?xml version="1.0"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"> <Table Foo="Bar" ss:ExpandedColumnCount="7"> </Table> </Workbook> XML; $sxml = new SimpleXMLElement($xml); /** * Access attribute of default namespace */ var_dump((string) $sxml->Table[0]['Foo']); // outputs: 'Bar' /** * Access attribute of non-default namespace */ var_dump((int) $sxml->Table[0]['ExpandedColumnCount']); // outputs: 0 var_dump((int) $sxml->Table[0]->attributes('ss', TRUE)->ExpandedColumnCount); // outputs: '7' ?> ---- Server IP: 62.2.182.223 Probable Submitter: 77.58.126.233 ---- Manual Page -- http://www.php.net/manual/en/simplexmlelement.attributes.php Edit -- https://master.php.net/note/edit/108029 Del: integrated -- https://master.php.net/note/delete/108029/integrated Del: useless -- https://master.php.net/note/delete/108029/useless Del: bad code -- https://master.php.net/note/delete/108029/bad+code Del: spam -- https://master.php.net/note/delete/108029/spam Del: non-english -- https://master.php.net/note/delete/108029/non-english Del: in docs -- https://master.php.net/note/delete/108029/in+docs Del: other reasons-- https://master.php.net/note/delete/108029 Reject -- https://master.php.net/note/reject/108029 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186786) next »