tags:

views:

104

answers:

1

Ok, check out this voodoo:

This code:

$xml = new SimpleXMLElement($xml);
 $var = $xml->QBXMLMsgsRs->ClassQueryRs;
 $vars = print_r($var,true);

Returns:

    SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [requestID] => Q2xhc3NRdWVyeXw1
            [statusCode] => 0
            [statusSeverity] => Info
            [statusMessage] => Status OK
        )

    [ClassRet] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [ListID] => 80000002-1241128424
                    [TimeCreated] => 2009-04-30T17:53:44-05:00
                    [TimeModified] => 2009-04-30T17:53:44-05:00
                    [EditSequence] => 1241128424
                    [Name] => D1
                    [FullName] => D1
                    [IsActive] => true
                    [Sublevel] => 0
                )

            [1] => SimpleXMLElement Object
                (
                    [ListID] => 80000001-1241128320
                    [TimeCreated] => 2009-04-30T17:52:00-05:00
                    [TimeModified] => 2009-04-30T17:52:00-05:00
                    [EditSequence] => 1241128320
                    [Name] => K1
                    [FullName] => K1
                    [IsActive] => true
                    [Sublevel] => 0
                )

            [2] => SimpleXMLElement Object
                (
                    [ListID] => 80000003-1241128452
                    [TimeCreated] => 2009-04-30T17:54:12-05:00
                    [TimeModified] => 2009-04-30T17:54:12-05:00
                    [EditSequence] => 1241128452
                    [Name] => S1
                    [FullName] => S1
                    [IsActive] => true
                    [Sublevel] => 0
                )
        )

)

However, this code:

$xml = new SimpleXMLElement($xml);
 $var = $xml->QBXMLMsgsRs->ClassQueryRs->ClassRet;
 $vars = print_r($var,true);

Returns:

SimpleXMLElement Object
(
    [ListID] => 80000002-1241128424
    [TimeCreated] => 2009-04-30T17:53:44-05:00
    [TimeModified] => 2009-04-30T17:53:44-05:00
    [EditSequence] => 1241128424
    [Name] => D1
    [FullName] => D1
    [IsActive] => true
    [Sublevel] => 0
)

For the life of me, I cannot access the rest of this object! Echo, print_r.... if I try to access the specific variable, it disappears!

+3  A: 

PHP's SimpleXml is an object that implements the ArrayAccess interface which means that you can reference elements with the array style syntax.

Asaph
FYI: This question has been asked before: http://stackoverflow.com/questions/664221/how-does-simple-xml-use-the-operator
Asaph
When I try to access it as an array, I get nothing. When I access it as an object, I only get the first result.
Citizen
Can you post your xml too so we can test and reproduce the issue?
Asaph