我从Xpath得到了非常奇怪的结果我正在使用PHP 5.5.12
有我的xml
<ResultData>
<Group>
<Group>
<HLRSN>1</HLRSN>
<IMSI>400026000243834</IMSI>
</Group>
<Group>
<ISDN>994558460243</ISDN>
</Group>
<Group>
<IMEI>3531870740891978</IMEI>
</Group>
<Group>
<CardType>SIM</CardType>
<NAM>BOTH</NAM>
<CATEGORY>COMMON</CATEGORY>
<SUB_AGE>52</SUB_AGE>
</Group>
</Group>
<Group Name =""LOCK"" >
<GSM_IC>FALSE</GSM_IC>
<GSM_OC>FALSE</GSM_OC>
</Group>
<Group>
<GPRSLOCK>FALSE</GPRSLOCK>
</Group>
<Group Name =""SABLOCK"" >
<SABLOCK_IC>FALSE</SABLOCK_IC>
<SABLOCK_OC>FALSE</SABLOCK_OC>
</Group>
<Group Name =""Basic Service"" >
<Group>
<TS>Telephony (TS11)</TS>
<TS>Emergency Call (TS12)</TS>
<TS>Short Message MT_PP (TS21)</TS>
<TS>Short Message MO_PP (TS22)</TS>
</Group>
<Group>
<BS>General-DataCDS (BS30)</BS>
</Group>
</Group>
<Group>
<DEFAULTCALL_TS>Telephony (TS11)</DEFAULTCALL_TS>
</Group>
<Group Name =""ODB Data"" >
<ODBSS>FALSE</ODBSS>
<ODBOC>NOBOC</ODBOC>
<ODBIC>NOBIC</ODBIC>
<ODBPB1>FALSE</ODBPB1>
<ODBPB2>FALSE</ODBPB2>
<ODBPB3>FALSE</ODBPB3>
<ODBPB4>FALSE</ODBPB4>
<ODBENTE>FALSE</ODBENTE>
<ODBINFO>FALSE</ODBINFO>
<ODBROAM>NOBAR</ODBROAM>
<ODBRCF>NOBRCF</ODBRCF>
<ODBECT>NOBECT</ODBECT>
<ODBDECT>FALSE</ODBDECT>
<ODBMECT>FALSE</ODBMECT>
<ODBPOS>NOBPOS</ODBPOS>
<ODBPOSTYPE>BOTH</ODBPOSTYPE>
<ODBENTEROAM>FALSE</ODBENTEROAM>
<ODBINFOROAM>FALSE</ODBINFOROAM>
</Group>
<Group Name =""SS Data"" >
<Group>
<CFU>PROV</CFU>
<CFU_NCS>TRUE</CFU_NCS>
<CFU_COU>SUBSCRIBER</CFU_COU>
</Group>
<Group>
<CFU_BSG>ALL</CFU_BSG>
<CFU_STATUS>PROV</CFU_STATUS>
</Group>
<Group>
<CFB>PROV</CFB>
<CFB_NFS>FALSE</CFB_NFS>
<CFB_NCS>TRUE</CFB_NCS>
<CFB_COU>SUBSCRIBER</CFB_COU>
</Group>
<Group>
<CFB_BSG>ALL</CFB_BSG>
<CFB_STATUS>PROV</CFB_STATUS>
</Group>
<Group>
<CFNRY>PROV</CFNRY>
<CFNRY_NFS>FALSE</CFNRY_NFS>
<CFNRY_NCS>TRUE</CFNRY_NCS>
<CFNRY_COU>SUBSCRIBER</CFNRY_COU>
</Group>
<Group>
<CFNRY_BSG>ALL</CFNRY_BSG>
<CFNRY_STATUS>PROV</CFNRY_STATUS>
</Group>
<Group>
<CFNRC>PROV</CFNRC>
<CFNRC_NCS>TRUE</CFNRC_NCS>
<CFNRC_COU>SUBSCRIBER</CFNRC_COU>
</Group>
<Group>
<CFNRC_BSG>ALL</CFNRC_BSG>
<CFNRC_STATUS>PROV</CFNRC_STATUS>
</Group>
<Group>
<CFD>NOTPROV</CFD>
</Group>
<Group>
<BAOC>PROV</BAOC>
<BOIC>PROV</BOIC>
<BOICEXHC>PROV</BOICEXHC>
<BORO>NOTPROV</BORO>
<BAIC>PROV</BAIC>
<BICROAM>PROV</BICROAM>
<CBCOU>SUBSCRIBER</CBCOU>
<CLIP>PROV</CLIP>
<CLIR>PROV</CLIR>
<COLP>NOTPROV</COLP>
<COLR>NOTPROV</COLR>
<ECT>NOTPROV</ECT>
<CW>NOTPROV</CW>
<HOLD>PROV</HOLD>
<MPTY>PROV</MPTY>
<MC>NOTPROV</MC>
<AOCI>NOTPROV</AOCI>
<AOCC>NOTPROV</AOCC>
<CUG>NOTPROV</CUG>
<UUS1>NOTPROV</UUS1>
<UUS2>NOTPROV</UUS2>
<UUS3>NOTPROV</UUS3>
<SMSCF>NOTPROV</SMSCF>
<plmn-specificSS-1>NOTPROV</plmn-specificSS-1>
<plmn-specificSS-2>NOTPROV</plmn-specificSS-2>
<plmn-specificSS-3>NOTPROV</plmn-specificSS-3>
<plmn-specificSS-4>NOTPROV</plmn-specificSS-4>
<plmn-specificSS-5>NOTPROV</plmn-specificSS-5>
<plmn-specificSS-6>NOTPROV</plmn-specificSS-6>
<plmn-specificSS-7>NOTPROV</plmn-specificSS-7>
<plmn-specificSS-8>NOTPROV</plmn-specificSS-8>
<plmn-specificSS-9>NOTPROV</plmn-specificSS-9>
<plmn-specificSS-A>NOTPROV</plmn-specificSS-A>
<plmn-specificSS-B>NOTPROV</plmn-specificSS-B>
<plmn-specificSS-C>NOTPROV</plmn-specificSS-C>
<plmn-specificSS-D>NOTPROV</plmn-specificSS-D>
<plmn-specificSS-E>PROV</plmn-specificSS-E>
<plmn-specificSS-F>NOTPROV</plmn-specificSS-F>
<CNAP>NOTPROV</CNAP>
</Group>
</Group>
<Group>
<Group Name =""O-CSI"" >
<OCSI_ID>2</OCSI_ID>
<OCSI_NAME>O-CSI400C</OCSI_NAME>
<OCSISTATE>TRUE</OCSISTATE>
</Group>
<Group Name =""T-CSI"" >
<TCSI_ID>2</TCSI_ID>
<TCSI_NAME>T-CSI400C</TCSI_NAME>
<TCSISTATE>TRUE</TCSISTATE>
</Group>
<Group Name =""MO-SMS-CSI"" >
<SMSCSI_ID>2</SMSCSI_ID>
<SMSCSI_NAME>SMSCSI400C</SMSCSI_NAME>
<MOSMSCSISTATE>TRUE</MOSMSCSISTATE>
</Group>
<Group Name =""U-CSI"" >
<UCSI_ID>1</UCSI_ID>
<UCSI_NAME>USSD_ID_1</UCSI_NAME>
</Group>
<Group Name =""TIF-CSI"" >
<TIFCSI>NOTPROV</TIFCSI>
</Group>
</Group>
<Group Name =""GPRS Data"" >
<Group>
<CHARGE_GLOBAL>NONE</CHARGE_GLOBAL>
</Group>
<Group>
<CNTXID>1</CNTXID>
<PDPTYPE>IPV4</PDPTYPE>
<ADDIND>DYNAMIC ADDRESS</ADDIND>
<VPLMN>FALSE</VPLMN>
<CHARGE>NONE</CHARGE>
<APNTPLID>9</APNTPLID>
<QOSTPLID>11</QOSTPLID>
</Group>
<Group>
<CNTXID>3</CNTXID>
<PDPTYPE>IPV4</PDPTYPE>
<ADDIND>DYNAMIC ADDRESS</ADDIND>
<VPLMN>FALSE</VPLMN>
<CHARGE>NONE</CHARGE>
<APNTPLID>8</APNTPLID>
<QOSTPLID>11</QOSTPLID>
</Group>
<Group>
<CNTXID>4</CNTXID>
<PDPTYPE>IPV4</PDPTYPE>
<ADDIND>DYNAMIC ADDRESS</ADDIND>
<VPLMN>FALSE</VPLMN>
<CHARGE>NONE</CHARGE>
<APNTPLID>1</APNTPLID>
<QOSTPLID>11</QOSTPLID>
</Group>
</Group>
<Group>
<SMDP>MSC</SMDP>
<ALS>NOTPROV</ALS>
<VVDN>NOTPROV</VVDN>
<ARD>NOTPROV</ARD>
<CARP>NOTPROV</CARP>
<RROption>ALL_PLMNS</RROption>
<VBS>NOTPROV</VBS>
<VGCS>NOTPROV</VGCS>
<EMLPP>NOTPROV</EMLPP>
<FMInit>NOTPROV</FMInit>
<FMSupervisor>NOTPROV</FMSupervisor>
<FMRemote>NOTPROV</FMRemote>
<IST>NOTPROV</IST>
<DIC>NOTPROV</DIC>
</Group>
<Group Name =""Dynamic Status Information For GSM"" >
<BaocForVlrRestrict>FALSE</BaocForVlrRestrict>
<Group>
<VlrNum>994550000121</VlrNum>
<MscNum>994550000121</MscNum>
<MsPurgedForNonGprs>FALSE</MsPurgedForNonGprs>
<VLRInHplmn>TRUE</VLRInHplmn>
<VLRInHomeCountry>TRUE</VLRInHomeCountry>
<VLRInArea>TRUE</VLRInArea>
<RequireCheckSS>FALSE</RequireCheckSS>
<RoamingRestrictInMscDueToUnsupportedFeature>FALSE</RoamingRestrictInMscDueToUnsupportedFeature>
<MscOrVlrAreaRoamingRestrict>FALSE</MscOrVlrAreaRoamingRestrict>
<ODBarredForUnsupportedCamel>FALSE</ODBarredForUnsupportedCamel>
<SupportedCamelPhase1>TRUE</SupportedCamelPhase1>
<SupportedCamelPhase2>TRUE</SupportedCamelPhase2>
<SupportedCamelPhase3>TRUE</SupportedCamelPhase3>
<SupportedCamelPhase4>FALSE</SupportedCamelPhase4>
<SRIMsrnCfActive>TRUE</SRIMsrnCfActive>
<ZoneCodeStatusAtMsc>zoneCodesSupported</ZoneCodeStatusAtMsc>
<longGroupIDSupported>FALSE</longGroupIDSupported>
<basicISTSupported>FALSE</basicISTSupported>
<istCommandSupported>FALSE</istCommandSupported>
<SuperChargerSupportedForGsm>FALSE</SuperChargerSupportedForGsm>
<ECATEGORYAtMsc>FALSE</ECATEGORYAtMsc>
<CS-MSISDN-LESS>FALSE</CS-MSISDN-LESS>
<CsUplStatus>Normal</CsUplStatus>
</Group>
</Group>
<Group Name =""Dynamic Status Information For GPRS"" >
<SgsnNum>994550000391</SgsnNum>
<SgsnAddressType>IPV4</SgsnAddressType>
<SgsnAddress>5.44.32.76</SgsnAddress>
<SgsnInHplmn>TRUE</SgsnInHplmn>
<MsPurgedForGprs>FALSE</MsPurgedForGprs>
<SgsnInHomeCountry>TRUE</SgsnInHomeCountry>
<SgsnInArea>TRUE</SgsnInArea>
<RoamingRestrictInSgsnDueToUnsupportedFeature>FALSE</RoamingRestrictInSgsnDueToUnsupportedFeature>
<SgsnAreaRoamingRestrict>FALSE</SgsnAreaRoamingRestrict>
<ODBarredForUnsupportedCamelForGprs>FALSE</ODBarredForUnsupportedCamelForGprs>
<PS-MSISDN-LESS>FALSE</PS-MSISDN-LESS>
<PsUplStatus>Normal</PsUplStatus>
</Group>
<Group>
<SupportedCamelPhase3_SGSN>TRUE</SupportedCamelPhase3_SGSN>
<SupportedCamelPhase4_SGSN>FALSE</SupportedCamelPhase4_SGSN>
<SuperChargerSupportedForGprs>networkNode_AreaRestricted</SuperChargerSupportedForGprs>
<ZoneCodeStatusAtSgsn>zoneCodesSupported</ZoneCodeStatusAtSgsn>
</Group>
<Group Name =""Short Message Dynamic Data for GSM"" >
<MCEFforGSM>FALSE</MCEFforGSM>
<MNRF>FALSE</MNRF>
<MNRRforGSM>No Reason for Non-GPRS</MNRRforGSM>
</Group>
<Group Name =""Short Message Dynamic Data for GPRS"" >
<MCEFforGPRS>FALSE</MCEFforGPRS>
<MNRG>FALSE</MNRG>
<MNRRforGPRS>No Reason</MNRRforGPRS>
<SupportedShortMessageMTPP>TRUE</SupportedShortMessageMTPP>
<SupportedShortMessageMOPP>TRUE</SupportedShortMessageMOPP>
</Group>
<Group Name =""ODB Supported Features For GSM"" >
<BarredSSAccess>TRUE</BarredSSAccess>
<BarredOutgoingEntertainmentCall>TRUE</BarredOutgoingEntertainmentCall>
<BarredOutgoingInformationCall>TRUE</BarredOutgoingInformationCall>
<SupGSMODB-BarredOutgoingInternationalCallExHC>TRUE</SupGSMODB-BarredOutgoingInternationalCallExHC>
<SupGSMODB-BarredOutgoingInternationalCall>TRUE</SupGSMODB-BarredOutgoingInternationalCall>
<SupGSMODB-BarredAllOutgoingCall>TRUE</SupGSMODB-BarredAllOutgoingCall>
<BarredAllECT>TRUE</BarredAllECT>
<BarredChargeableECT>TRUE</BarredChargeableECT>
<BarredInternationalECT>TRUE</BarredInternationalECT>
<BarredInterzonalECT>TRUE</BarredInterzonalECT>
<BarredDECT>TRUE</BarredDECT>
<BarredMECT>TRUE</BarredMECT>
</Group>
<Group Name =""ODB Supported Features For GPRS"" >
<SupGPRSODB-BarredAllOutgoingCall>TRUE</SupGPRSODB-BarredAllOutgoingCall>
<SupGPRSODB-BarredOutgoingInternationalCall>TRUE</SupGPRSODB-BarredOutgoingInternationalCall>
<SupGPRSODB-BarredOutgoingInternationalCallExHC>TRUE</SupGPRSODB-BarredOutgoingInternationalCallExHC>
<BarringofPacketOrientedServices>TRUE</BarringofPacketOrientedServices>
</Group>
<Group Name =""Supported LCS"" >
<MSCSupportedLCSCapabilitySet1>TRUE</MSCSupportedLCSCapabilitySet1>
<MSCSupportedLCSCapabilitySet2>FALSE</MSCSupportedLCSCapabilitySet2>
<SGSNSupportedLCSCapabilitySet2>TRUE</SGSNSupportedLCSCapabilitySet2>
</Group>
<Group Name =""Featured Service Supported Features"" >
<ALS_DYN>FALSE</ALS_DYN>
<VVDN_DYN>FALSE</VVDN_DYN>
</Group></ResultData>
我正在尝试查询所有TS,这是微不足道的简单
$xml = simplexml_load_string($tmpstr);
$smsts = $xml->xpath('//TS');
var_dump($smsts);
在线编辑器甚至在Notepad ++查询中返回4个非空元素,但我的php代码返回以下输出:
array(4) { [0]=> object(SimpleXMLElement)#54 (0) { } [1]=> object(SimpleXMLElement)#55 (0) { } [2]=> object(SimpleXMLElement)#56 (0) { } [3]=> object(SimpleXMLElement)#57 (1) { [0]=> string(26) "Short Message MO_PP (TS22)" } }
包含4个元素的数组,但其中3个为空o_O 怎么了?我只是无法得到它:(
顺便说一下,它是SOAP结果,我只修剪了#34; ResultData&#34;之外的所有其他元素。因为simplexml_load_string只返回第一个子数据,第二个子节点为空。
答案 0 :(得分:0)
如果您执行以下操作:
$xml = simplexml_load_string($tmpstr); $smsts = $xml->xpath('//TS'); foreach ($smsts as $element){ echo $element; }
它应该回显所有的值。
如果你需要字符串中的所有值,你可以这样:
$xml = simplexml_load_string($tmpstr); $smsts = $xml->xpath('//TS'); $values = null; foreach ($smsts as $element){ $values .= ' '.$element; } echo $values;