0

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!

1
  • "You keep using that word. I do not think it means what you think it means." ;) Commented Sep 18, 2009 at 1:29

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

3 Comments

FYI: This question has been asked before: stackoverflow.com/questions/664221/…
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.
Can you post your xml too so we can test and reproduce the issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.