Re: Starting with XML

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 30 Oct 2013, at 13:43, leam hall <leamhall@xxxxxxxxx> wrote:

> I'm trying to work on an XML document and turn it into something I can put
> into a database or array. Am getting stuck as I try to learn the PHP stuff
> needed for XML.
> 
> What I have so far is just:
> 
> $xml = simplexml_load_file('my-file.xml');
> 
> $status = $xml->status;
> echo "status is $status.\n";
> 
> $href = $xml->reference->href;
> echo "href is $href.\n";
> 
> Which gives:
> 
> status is accepted.
> href is .
> 
> 
> If I do:
> 
>    print_r($xml);
> 
> It starts out with:
> 
> SimpleXMLElement Object
> (
>    [@attributes] => Array
>        (
>            [id] => My_Info
>        )
> 
>    [status] => accepted
>    [title] => Nice long string title
>    [reference] => SimpleXMLElement Object
>        (
>            [@attributes] => Array
>                (
>                    [href] => http://www.example.com
>                )
> 
>        )
> 
> 
> 
> How do I reference the nested objects? The file is fairly long and seems
> deeply nested.

The value you’re trying to retrieve is an attribute, and can be accessed using the attributes method: http://php.net/simplexmlelement.attributes

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux