请注意“ @”属性和破折号,例如“ MAP-SETS” SimpleXML输出转储示例:
object(SimpleXMLElement)#1 (5) { ["@attributes"]=> array(8) { ["date"]=> string(10) "2013-07-30" ["equipment"]=> string(16) "RANGER 2" ["id"]=> string(5) "B0.17" ["name"]=> string(14) "abcdefg" ["sn"]=> string(9) "012345" ["time"]=> string(8) "06:24:24" ["trademark"]=> string(24) "ELECTRON, INC" ["version"]=> string(3) "1.0" } ["MAP-SETS"]=> object(SimpleXMLElement)#2 (1) { ["MAP-SET"]=> array(9) { [0]=> object(SimpleXMLElement)#6 (1) { ["@attributes"]=> array(5) { ["band"]=> string(11) "TERRESTRIAL" ["date"]=> string(10) "2017-10-05" ["equipment"]=> string(6) "RANGER" ["name"]=> string(13) "AMP-ANT1" ["version"]=> string(3) "1.1" } } [1]=> object(SimpleXMLElement)#7 (1) { ["@attributes"]=> array(5) { ["band"]=> string(11) "TERRESTRIAL" ["date"]=> string(10) "2017-10-05" ["equipment"]=> string(6) "RANGER" ["name"]=> string(13) "AMP-ANT2" ["version"]=> string(3) "1.1" } } [2]=> object(SimpleXMLElement)#8 (1) { ["@attributes"]=> array(5) { ["band"]=> string(11) "TERRESTRIAL" ["date"]=> string(10) "2017-07-25" ["equipment"]=> string(6) "RANGER" ["name"]=> string(13) "AMP-ANT3" ["version"]=> string(3) "1.1" } } [3]=> object(SimpleXMLElement)#9 (1) { ["@attributes"]=> array(5) { ["band"]=> string(11) "TERRESTRIAL" ["date"]=> string(10) "2018-09-10" ["equipment"]=> string(6) "RANGER" ["name"]=> string(13) "AMP-ANT4" ["version"]=> string(3) "1.1" } } [4]=> object(SimpleXMLElement)#10 (1) { ["@attributes"]=> array(5) { ["band"]=> string(11) "TERRESTRIAL" ["date"]=> string(10) "2017-10-05" ["equipment"]=> string(6) "RANGER" ["name"]=> string(13) "AMP-ANT5" ["version"]=> string(3) "1.1" } } [5]=> object(SimpleXMLElement)#11 (1) { ["@attributes"]=> array(5) { ["band"]=> string(11) "TERRESTRIAL" ["date"]=> string(10) "2017-07-25" ["equipment"]=> string(6) "RANGER" ["name"]=> string(13) "AMP-ANT8" ["version"]=> string(3) "1.1" } } [6]=> object(SimpleXMLElement)#12 (1) { ["@attributes"]=> array(5) { ["band"]=> string(11) "TERRESTRIAL" ["date"]=> string(10) "2017-07-25" ["equipment"]=> string(6) "RANGER" ["name"]=> string(13) "AMP-ANT9" ["version"]=> string(3) "1.1" } } [7]=> object(SimpleXMLElement)#13 (1) { ["@attributes"]=> array(5) { ["band"]=> string(11) "TERRESTRIAL" ["date"]=> string(10) "2018-09-10" ["equipment"]=> string(6) "RANGER" ["name"]=> string(13) "AMP-ANT6" ["version"]=> string(3) "1.1" } } [8]=> object(SimpleXMLElement)#14 (1) { ["@attributes"]=> array(5) { ["band"]=> string(11) "TERRESTRIAL" ["date"]=> string(10) "2018-09-10" ["equipment"]=> string(6) "RANGER" ["name"]=> string(13) "AMP-ANT7" ["version"]=> string(3) "1.1" } } } } ["ATTENUATION-TESTS"]=> object(SimpleXMLElement)#3 (0) { } ["OPTIONS"]=> object(SimpleXMLElement)#4 (3) { ["CAPTURE-PSI"]=> object(SimpleXMLElement)#14 (1) { ["@attributes"]=> array(1) { ["value"]=> string(5) "false" } } ["PAUSE-CHSETS"]=> object(SimpleXMLElement)#13 (1) { ["@attributes"]=> array(1) { ["value"]=> string(4) "true" } } ["FSM"]=> object(SimpleXMLElement)#12 (1)
这有效: $ xml = simplexml_load_file(“ test.XML”); var_dump($ xml);
但是当我尝试调用单个项目时,根据我的操作,会出现不同的错误。例如:意外的[[,期望的标识符(T_STRING)或变量(T_VARIABLE) 此示例不起作用:
echo $xml->["@attributes"][0]->["MAP-SETS"] . "<br>";
我说错什么吗? 我可以从其他xml文件示例中获取其他代码,这些代码不包含特殊字符,例如:“
foreach ($movies->movie->characters->character as $character) {
echo $character->name, ' played by ', $character->actor, PHP_EOL;
XML源示例:
<?xml version="1.0" encoding="utf-8"?>
<DATALOGGER date="2013-07-30" equipment="RANGER 2" id="B0.17" name="abcdefg" sn="012345" time="06:24:24" trademark="PROMAX ELECTRONICA, S.L." version="1.0" xmlns:xi="http://www.w3.org/2001/XInclude" >
<CHANNEL-SETS>
<CHANNEL-SET band="TERRESTRIAL" date="2017-10-05" equipment="RANGER 2" name="AMP-ANT1" version="1.1" />
<CHANNEL-SET band="TERRESTRIAL" date="2017-10-05" equipment="RANGER 2" name="AMP-ANT2" version="1.1" />
</CHANNEL-SETS>
<ATTENUATION-TESTS />
<OPTIONS>
<CAPTURE-PSI value="false" />
<PAUSE-CHSETS value="true" />
<FSM value="false" />
</OPTIONS>
<TEST>
<POINT name="201.08.32" date="2013-07-30" time="06:25:29" >
<GPS latitude="0.0000000" longitude="0.0000000" locked="false" />
<CHANNEL-SET band="TERRESTRIAL" date="2017-10-05" equipment="RANGER 2" name="AMP-ANT1" time="06:25:33" version="1.1" >
<CHANNEL name="XNSA-1" frequency="491.00" units="MHz" date="2013-07-30" time="06:27:46" >
<MEASUREMENTS>
<ATSC>
<PARAMETERS>
<BANDWIDTH value="6000" units="kHz" />
<SPECTRALINVERSION value="OFF" />
<CONSTELLATION value="8VSB" />
</PARAMETERS>
<MEASURES>
<POWER value="-2.6" range="IN" units="dBmV" />
<CN value="35.2" range="OVER" units="dB" />
<OFFSET value="-1.0" range="IN" units="kHz" />
<MER value="35.1" range="IN" units="dB" />
<SER value="1.0E-04" range="UNDER" />
<VBER value="1.0E-07" range="UNDER" />
<LM value="19.9" range="IN" units="dB" />
</MEASURES>
<STATUS value="MPEG2 TS locked" locked="LOCKED" />
</ATSC>
</MEASUREMENTS>
</CHANNEL>
<CHANNEL name="XNSA-2" frequency="521.00" units="MHz" date="2013-07-30" time="06:27:53" >
<MEASUREMENTS>
<ATSC>
<PARAMETERS>
<BANDWIDTH value="6000" units="kHz" />
<SPECTRALINVERSION value="OFF" />
<CONSTELLATION value="8VSB" />
</PARAMETERS>
<MEASURES>
<POWER value="1.8" range="IN" units="dBmV" />
<CN value="40.1" range="OVER" units="dB" />
<OFFSET value="-1.0" range="IN" units="kHz" />
<MER value="36.0" range="OVER" units="dB" />
<SER value="1.0E-04" range="UNDER" />
<VBER value="1.0E-07" range="UNDER" />
<LM value="20.8" range="IN" units="dB" />
</MEASURES>
<STATUS value="MPEG2 TS locked" locked="LOCKED" />
</ATSC>
</MEASUREMENTS>
</CHANNEL>
<CHANNEL name="XNSA-3" frequency="527.00" units="MHz" date="2013-07-30" time="06:28:03" >
<MEASUREMENTS>
<ATSC>
<PARAMETERS>
<BANDWIDTH value="6000" units="kHz" />
<SPECTRALINVERSION value="OFF" />
<CONSTELLATION value="8VSB" />
</PARAMETERS>
<MEASURES>
<POWER value="1.8" range="IN" units="dBmV" />
<CN value="40.8" range="OVER" units="dB" />
<OFFSET value="-1.0" range="IN" units="kHz" />
<MER value="35.6" range="IN" units="dB" />
<SER value="1.0E-04" range="UNDER" />
<VBER value="1.0E-07" range="UNDER" />
<LM value="20.4" range="IN" units="dB" />
</MEASURES>
<STATUS value="MPEG2 TS locked" locked="LOCKED" />
</ATSC>
</MEASUREMENTS>
</CHANNEL>
</CHANNEL-SET>
<CHANNEL-SET band="TERRESTRIAL" date="2017-10-05" equipment="RANGER 2" name="AMP-ANT2" time="06:25:33" version="1.1" >
<CHANNEL name="XDoD-12" frequency="491.00" units="MHz" date="2013-07-30" time="06:28:39" >
<MEASUREMENTS>
<ATSC>
<PARAMETERS>
<BANDWIDTH value="6000" units="kHz" />
<SPECTRALINVERSION value="OFF" />
<CONSTELLATION value="8VSB" />
</PARAMETERS>
<MEASURES>
<POWER value="-2.7" range="IN" units="dBmV" />
<CN value="39.4" range="OVER" units="dB" />
<OFFSET value="-1.0" range="IN" units="kHz" />
<MER value="25.6" range="IN" units="dB" />
<SER value="1.0E-04" range="UNDER" />
<VBER value="1.0E-07" range="UNDER" />
<LM value="10.4" range="IN" units="dB" />
</MEASURES>
<STATUS value="MPEG2 TS locked" locked="LOCKED" />
</ATSC>
</MEASUREMENTS>
</CHANNEL>
</POINT>
</TEST>
</DATALOGGER>