2

This is related to my earlier question here: Trying to read XML nodes using PHP DOM

I have an array which has elements that look like this:

[rpc.pingomatic.com] => Array
        (
            [http://www.example.com] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [name] => flerror
                            [value] => SimpleXMLElement Object
                                (
                                    [boolean] => 0
                                )

                        )

                    [1] => SimpleXMLElement Object
                        (
                            [name] => message
                            [value] => SimpleXMLElement Object
                                (
                                    [string] => Pings being forwarded to 11 services!
                                )

                        )
            )

I want to retrieve the data and finally display it in this manner:
flerror:0
Message from directory:Pings being forwarded to 11 services

I can use this to retrieve the necessary fields:

echo $response->name;                   
echo $response->value->boolean;
echo $response->value->string;

However, I am using a foreach loop to traverse through the array, and not all elements have the fields named boolean and string. They might have something like flag instead of boolean, etc.

Is there a generic way to retrieve the necessary data using the same foreach loop?

2 Answers 2

0

You could use this method PHP: SimpleXMLElement::xpath - Manual

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

2 Comments

There are a lot of examples in the comment section at the page given above.
Besides, there are a lot of related questions. One of them is stackoverflow.com/questions/3108721/…
0

I figured the best way to deal with my problem is to use isset($response->value->boolean) or isset($response->value->string) to ascertain the type of the value and echo it out.

Comments

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.