Check this out:
$user = simplexml_load_file('user.xml');
echo (string)$user->name[0]['first_name'] . "\n";
echo (string)$user->name[0]['last_name'] . "\n";
echo $user->name . "\n";
Let me know if that helps!
On Fri, Jul 12, 2013 at 4:17 PM, James Noble <[email protected]> wrote:
> I am having issues with some XML I receive from a third party. In the XML
> they populate both the content and the attributes of the XML. When I use
> simplexml_load_file I loose all the attributes for any tags that have data
> in the content area. Below is a very simple example and yes I know in this
> instance I can just combine the data.
>
> <user>
> <name first_name="John" last_name="White">John White</name>
> <phone area_code="801" prefix="555" subscriber="1234"></phone>
> </user>
>
> When I dump this file to the screen I get
> [0]=>SimpleXMLElement Object
> (
> [Name]=>John White
> [phone]
> (
> [@attributes]=>Array
> (
> [area_code]=> 801
> [prefix]=> 555
> [subscriber]=> 1234
> )
> )
> )
>
> Is there a way to get the attributes first_name and last_name as well as
> the content from simplexml_load_file?
>
> _______________________________________________
>
> UPHPU mailing list
> [email protected]
> http://uphpu.org/mailman/listinfo/uphpu
> IRC: #uphpu on irc.freenode.net
>
_______________________________________________
UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net