Returning a specific XML child with PHP -
I have something to do with some XML:
I may not have to retrieve a specific administrator, however, the following:
$ admin = "user1"; Foreign ($ $ subxml $ child) {if ($ child- & gt; admin- & gt; name == $ administrator) {var_dump ($ child); }}
Returns an array, including both user and user. How can I go about outputing only the selected user's XML (in this case user 1) then my desired output is:
& lt; Admin & gt; & Lt; Name & gt; User1 & lt; / Name & gt; & Lt; Authentication_source & gt; Local & lt; / Authentication_source & gt; & Lt; / Admin & gt;
Thanks!
Using XPATH might be a good idea
$ query = $ Simple_xml_resource- & gt; Xpath ('/ admin_list / admin [name =' '. $ Name]' "] '); if (count ($ query) == 0) {// no user found} and {$ user = $ query [0 ]; Resonate $ user-> asXML (); // output XML}}
Comments
Post a Comment