【发布时间】:2018-03-21 13:11:19
【问题描述】:
我正在试图弄清楚如何从以下 XML 中加载变量 location、time 和 val。
XML 如下所示:
<root xmlns="">
<sns id="1" name="Senzor A" type="1" status="0" unit="0" val="4.5" w-min="" w-max=""/>
<status level="2" location="AAA" time="03/21/2018 14:09:08"/>
</root>
解析后的 XML 如下所示:
object(SimpleXMLElement)#1 (2) {
["sns"]=>
object(SimpleXMLElement)#2 (1) {
["@attributes"]=>
array(8) {
["id"]=>
string(1) "1"
["name"]=>
string(8) "Senzor A"
["type"]=>
string(1) "1"
["status"]=>
string(1) "0"
["unit"]=>
string(1) "0"
["val"]=>
string(3) "4.5"
["w-min"]=>
string(0) ""
["w-max"]=>
string(0) ""
}
}
["status"]=>
object(SimpleXMLElement)#3 (1) {
["@attributes"]=>
array(3) {
["level"]=>
string(1) "2"
["location"]=>
string(3) "AAA"
["time"]=>
string(19) "03/21/2018 14:09:08"
}
}
}
我很难弄清楚如何导航,所以如果有人能给我一些建议,我将不胜感激。
【问题讨论】: