解析后
无法从此数组访问该对象<abc>
<ls:location>
<ls:address1>No 16 GLama</ls:address1>
<ls:city>Kuala Lumpur</ls:city>
<ls:zip>58200</ls:zip>
<ls:latitude>3.092055</ls:latitude>
<ls:longitude>101.684757</ls:longitude>
</ls:location>
</abc>
如何访问zip对象
$x = new SimpleXmlElement($content);
答案 0 :(得分:1)
echo $x->location->zip;
//"58200"
答案 1 :(得分:0)
<?php
$content = '<abc>
<ls:location>
<ls:address1>No 16 GLama</ls:address1>
<ls:city>Kuala Lumpur</ls:city>
<ls:zip>58200</ls:zip>
<ls:latitude>3.092055</ls:latitude>
<ls:longitude>101.684757</ls:longitude>
</ls:location>
</abc>';
$x = new SimpleXmlElement($content);
// accessing the wanted value in the object
// returns zip as an object
$zip = $x->location->zip;
// object to string type conversion
$zip = (string) $zip;
assert('$zip == "58200" /* Expected result: zip = 58200. */');
?>