xml parsing - new to xml: Get children data into php variable -
i need mean , lean solution confirmation form. retrieve contact e-mail address server xml response. follows:
<users> <user loginname="test1" owner="" alias="" usertype="paid" clienttype="obm" quota="10737418240" timezone="gmt+08:00 (cst)" language="en" datafile="1" datasize="1536" retainfile="0" retainsize="0" enablemssql="y" enablemsexchange="y" enableoracle="y" enablelotusnotes="y" enablelotusdomino="y" enablemysql="y" enableinfiledelta="y" enableshadowcopy="y" enableexchangemailbox="n" exchangemailboxquota="0" enablenasclient="y" enabledeltamerge="y" enablemsvm="n" msvmquota="0" enablevmware="n" vmwarequota="0" bandwidth="0" notes="" status="enable" registrationdate="1302687743242" suspendpaiduser="n" suspendpaiduserdate="20140503" lastbackupdate="1302699594652" enablecdp="y" enableshadowprotectbaremetal="y" enablewinserver2008baremetal="y" hostname="123.abc.com"> <contact name=""email="www@qqq.com"/> </user> … </users>
i got far have next results:
object(simplexmlelement)#7 (1) { [0]=> string(6) "company" } object(simplexmlelement)#8 (1) { [0]=> string(26) "email@address.ext" }
now need variables. seem unable accomplisch this. code here:
$request = "http://$server/obs/api/getuser.do? sysuser=$sysuser&syspwd=$syspwd&loginname=$logonname"; // execute api phone call , place xml output in array variable $response = simplexml_load_file($request); // retrieve loginname attribute array foreach($response->children() $child) { foreach($child->attributes() $data) { echo var_dump($data); } }
any newbie help appriciated. give thanks you
frank
here's simple illustration of reading name , email out of xml:
$response = simplexml_load_file($request); foreach($response->user $user) { foreach($user->contact $contact) { $name = $contact->attributes()->name; $email = $contact->attributes()->email; echo $name; echo $email; } }
demo
php xml-parsing
No comments:
Post a Comment