Home  >  Article  >  Backend Development  >  如何能知道XML对象中有几个一层的元素 simplexml_load_file()

如何能知道XML对象中有几个一层的元素 simplexml_load_file()

WBOY
WBOYOriginal
2016-06-13 12:34:48767browse

怎么能知道XML对象中有几个一层的元素 simplexml_load_file()
比如:simplexml_load_file() 后用var_dump()显示如下:
怎么能知道xml中包含几个page ?
下例中page是2个,一个[0],一个[1]. 



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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn