doudie2693 2016-09-28 11:42
浏览 142
已采纳

Xpath查询返回部分空值(PHP)

I got very strange result from Xpath I am using PHP 5.5.12

There is my 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 ="&quot;LOCK&quot;" >
    <GSM_IC>FALSE</GSM_IC>
    <GSM_OC>FALSE</GSM_OC>
</Group>
<Group>
    <GPRSLOCK>FALSE</GPRSLOCK>
</Group>
<Group Name ="&quot;SABLOCK&quot;" >
    <SABLOCK_IC>FALSE</SABLOCK_IC>
    <SABLOCK_OC>FALSE</SABLOCK_OC>
</Group>
<Group Name ="&quot;Basic Service&quot;" >
    <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 ="&quot;ODB Data&quot;" >
    <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 ="&quot;SS Data&quot;" >
    <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 ="&quot;O-CSI&quot;" >
        <OCSI_ID>2</OCSI_ID>
        <OCSI_NAME>O-CSI400C</OCSI_NAME>
        <OCSISTATE>TRUE</OCSISTATE>
    </Group>
    <Group Name ="&quot;T-CSI&quot;" >
        <TCSI_ID>2</TCSI_ID>
        <TCSI_NAME>T-CSI400C</TCSI_NAME>
        <TCSISTATE>TRUE</TCSISTATE>
    </Group>
    <Group Name ="&quot;MO-SMS-CSI&quot;" >
        <SMSCSI_ID>2</SMSCSI_ID>
        <SMSCSI_NAME>SMSCSI400C</SMSCSI_NAME>
        <MOSMSCSISTATE>TRUE</MOSMSCSISTATE>
    </Group>
    <Group Name ="&quot;U-CSI&quot;" >
        <UCSI_ID>1</UCSI_ID>
        <UCSI_NAME>USSD_ID_1</UCSI_NAME>
    </Group>
    <Group Name ="&quot;TIF-CSI&quot;" >
        <TIFCSI>NOTPROV</TIFCSI>
    </Group>
</Group>
<Group Name ="&quot;GPRS Data&quot;" >
    <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 ="&quot;Dynamic Status Information For GSM&quot;" >
    <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 ="&quot;Dynamic Status Information For GPRS&quot;" >
    <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 ="&quot;Short Message Dynamic Data for GSM&quot;" >
    <MCEFforGSM>FALSE</MCEFforGSM>
    <MNRF>FALSE</MNRF>
    <MNRRforGSM>No Reason for Non-GPRS</MNRRforGSM>
</Group>
<Group Name ="&quot;Short Message Dynamic Data for GPRS&quot;" >
    <MCEFforGPRS>FALSE</MCEFforGPRS>
    <MNRG>FALSE</MNRG>
    <MNRRforGPRS>No Reason</MNRRforGPRS>
    <SupportedShortMessageMTPP>TRUE</SupportedShortMessageMTPP>
    <SupportedShortMessageMOPP>TRUE</SupportedShortMessageMOPP>
</Group>
<Group Name ="&quot;ODB Supported Features For GSM&quot;" >
    <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 ="&quot;ODB Supported Features For GPRS&quot;" >
    <SupGPRSODB-BarredAllOutgoingCall>TRUE</SupGPRSODB-BarredAllOutgoingCall>
    <SupGPRSODB-BarredOutgoingInternationalCall>TRUE</SupGPRSODB-BarredOutgoingInternationalCall>
    <SupGPRSODB-BarredOutgoingInternationalCallExHC>TRUE</SupGPRSODB-BarredOutgoingInternationalCallExHC>
    <BarringofPacketOrientedServices>TRUE</BarringofPacketOrientedServices>
</Group>
<Group Name ="&quot;Supported LCS&quot;" >
    <MSCSupportedLCSCapabilitySet1>TRUE</MSCSupportedLCSCapabilitySet1>
    <MSCSupportedLCSCapabilitySet2>FALSE</MSCSupportedLCSCapabilitySet2>
    <SGSNSupportedLCSCapabilitySet2>TRUE</SGSNSupportedLCSCapabilitySet2>
</Group>
<Group Name ="&quot;Featured Service Supported Features&quot;" >
    <ALS_DYN>FALSE</ALS_DYN>
    <VVDN_DYN>FALSE</VVDN_DYN>
</Group></ResultData>

I am trying to query all TS it is trivial and simple

                $xml = simplexml_load_string($tmpstr);
                $smsts = $xml->xpath('//TS');
                var_dump($smsts);

IN online editors and even in Notepad++ query returns 4 not empty elements, but my php-code returns output below:

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)" } }

Array of 4 elements, but 3 of them are empty o_O What is wrong? I just cant get it :(

By the way it is SOAP-result, I just trim all other elements outside "ResultData" because simplexml_load_string returned only first child data, second child was empty.

  • 写回答

1条回答 默认 最新

  • dptdb84606 2016-09-28 13:17
    关注

    If you do something like:

    $xml = simplexml_load_string($tmpstr);
    $smsts = $xml->xpath('//TS');
    
    foreach ($smsts as $element){
        echo $element;
    }

    it should echo all the values.

    If you need all the values in a string you could so something like:

    $xml = simplexml_load_string($tmpstr);
    $smsts = $xml->xpath('//TS');
    
    $values = null;
    foreach ($smsts as $element){
        $values .= '  '.$element;
    }
    echo $values;
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办