How can I know there are several layers of elements in the XML object: simplexml_load_file ()

Source: Internet
Author: User
How can we know that the XML object contains several layers of elements simplexml_load_file (), such as simplexml_load_file (), and then var_dump () is shown as follows:
How many pages are contained in xml?
In the following example, there are two pages, one [0] and the other [1].



object(SimpleXMLElement)#24 (1) { ["page"]=> array(2) { [0]=> object(SimpleXMLElement)#25 (2) { ["@attributes"]=> array(1) { ["id"]=> string(1) "0" } ["background"]=> object(SimpleXMLElement)#38 (1) { ["@attributes"]=> array(1) { ["color"]=> string(11) "255,255,255" } } } [1]=> object(SimpleXMLElement)#26 (1) { ["@attributes"]=> array(1) { ["preview"]=> string(100) "" } } }}


Reply to discussion (solution)

$elem = simplexml_load_string($xml);var_dump($elem->count());

$elem = simplexml_load_string($xml);var_dump($elem->count());


Thank you. This function is only supported by php5.3 and above. I upgraded my 5.2 to 5.5 yesterday. However, it will be slow to refresh the page after it is opened-very slow


$elem = simplexml_load_string($xml);var_dump($elem->count());


Thank you. This function is only supported by php5.3 and above. I upgraded my 5.2 to 5.5 yesterday. However, it will be slow to refresh the page after it is opened-very slow
5.5 some functions are not backward compatible.
However, it should be faster than the previous version.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.