我寫了一個php代碼,用於從XML文件中將一些數據檢索到變量中。按索引不顯示數組元素
這是XML文件:
<Server>
<Server1>
<ipaddress>10.3.2.0</ipaddress>
<rootpassword>abcd</rootpassword>
<port>22</port>
<autousername>abcd</autousername>
<autopassword>abcd</autopassword>
</Server1>
<Server1>
<ipaddress>10.3.2.1</ipaddress>
<rootpassword>abcd</rootpassword>
<port>22</port>
<autousername>abcd</autousername>
<autopassword>abcd</autopassword>
</Server1>
<Server1>
<ipaddress>10.3.2.2</ipaddress>
<rootpassword>abcd</rootpassword>
<port>22</port>
<autousername>abcd</autousername>
<autopassword>abcd</autopassword>
</Server1>
<Server1>
<ipaddress>10.3.2.3</ipaddress>
<rootpassword>abcd</rootpassword>
<port>22</port>
<autousername>abcd</autousername>
<autopassword>abcd</autopassword>
</Server1>
</Server>
這是PHP代碼:
$x = $xmlDoc->getElementsByTagName("ipaddress");
在這裏,我想顯示的$x
通過索引值的內容,像
echo $x[0]->nodeValue;
我該怎麼做?
在這裏你去http://php.net/SimpleXML :) – EaterOfCode