<air:AirPricingInfo Key="J2GiU97Q2BKABKe1AAAAAA==" TotalPrice="USD663.70" BasePrice="GBP233.00" ApproximateTotalPrice="USD663.70" ApproximateBasePrice="USD310.00" EquivalentBasePrice="USD310.00" ApproximateTaxes="USD353.70" Taxes="USD353.70" LatestTicketingTime="2017-11-06T23:59:00.000-05:00" PricingMethod="Auto" Refundable="true" IncludesVAT="false" PlatingCarrier="WY" ProviderCode="1V">
<air:FareInfo Key="J2GiU97Q2BKALKe1AAAAAA==" FareBasis="NVE6MGB" PassengerTypeCode="ADT" Origin="MAN" Destination="DXB" EffectiveDate="2017-10-28T09:48:00.000-04:00" DepartureDate="2017-11-09" Amount="USD155.00" NotValidBefore="2017-11-09" NotValidAfter="2017-11-09" TaxAmount="USD220.70">
<air:FareRuleKey FareInfoRef="J2GiU97Q2BKALKe1AAAAAA==" ProviderCode="1V">6UUVoSldxwi3bYRYr8cIKsbKj3F8T9EyxsqPcXxP0TIjSPOlaHfQe5cuasWd6i8Dly5qxZ3qLwOXLmrFneovA5cuasWd6i8Dly5qxZ3qLwOXLmrFneovAxmyschz/qZvM3ExqSoG051W8N+Siiit9ZnGFThoE0iqQu0ZscBMSQ5d2/MbJh0jzdltclw4eGdWYibrzK0Ouv3G7OIYHTs6iRll6FxyIC6cYuAWfcH2w92IEQfz1U0L7yHdlLUXaJyB6STZDo2E3i3qkp0FEw0raOCbZ1nsUQQBLrDF4/ul0s6tkecSR34H+ouFsAExMoVlv4Xvb2u1Qx+/he9va7VDH7+F729rtUMfv4Xvb2u1Qx+/he9va7VDHzyxauAs+veBE308BFXsd7QPNqcmmS6r7B2WN4EjYakqaxRx0b5/L3T35IrCOmWUmvjyoufDRBrY5GwF8kqQiiA=</air:FareRuleKey>
</air:FareInfo>
<air:FareInfo Key="J2GiU97Q2BKAMKe1AAAAAA==" FareBasis="NVE6MGB" PassengerTypeCode="ADT" Origin="DXB" Destination="MAN" EffectiveDate="2017-10-28T09:48:00.000-04:00" DepartureDate="2017-11-16" Amount="USD155.00" NotValidBefore="2017-11-16" NotValidAfter="2017-11-16" TaxAmount="USD133.00">
<air:FareRuleKey FareInfoRef="J2GiU97Q2BKAMKe1AAAAAA==" ProviderCode="1V">6UUVoSldxwi3bYRYr8cIKsbKj3F8T9EyxsqPcXxP0TIjSPOlaHfQe5cuasWd6i8Dly5qxZ3qLwOXLmrFneovA5cuasWd6i8Dly5qxZ3qLwOXLmrFneovAxmyschz/qZvM3ExqSoG051cSlL+hx+N9VZDfT4YdB6B83f1UwCbb2Vd2/MbJh0jzdltclw4eGdWYibrzK0Ouv3SE6fqwbUqcRll6FxyIC6cYuAWfcH2w92IEQfz1U0L7yHdlLUXaJyB6STZDo2E3i3vWpSmZkrE0eCbZ1nsUQQB6KkuhxM2UfKtkecSR34H+ouFsAExMoVlv4Xvb2u1Qx+/he9va7VDH7+F729rtUMfv4Xvb2u1Qx+/he9va7VDHzyxauAs+veBE308BFXsd7QPNqcmmS6r7B2WN4EjYakqaxRx0b5/L3T35IrCOmWUmvjyoufDRBrY5GwF8kqQiiA=</air:FareRuleKey>
</air:FareInfo>
<air:BookingInfo BookingCode="N" CabinClass="Economy" FareInfoRef="J2GiU97Q2BKALKe1AAAAAA==" SegmentRef="J2GiU97Q2BKA2Je1AAAAAA==" HostTokenRef="J2GiU97Q2BKA/Je1AAAAAA==" />
<air:BookingInfo BookingCode="N" CabinClass="Economy" FareInfoRef="J2GiU97Q2BKALKe1AAAAAA==" SegmentRef="J2GiU97Q2BKA4Je1AAAAAA==" HostTokenRef="J2GiU97Q2BKA/Je1AAAAAA==" />
<air:BookingInfo BookingCode="N" CabinClass="Economy" FareInfoRef="J2GiU97Q2BKAMKe1AAAAAA==" SegmentRef="J2GiU97Q2BKA6Je1AAAAAA==" HostTokenRef="J2GiU97Q2BKAAKe1AAAAAA==" />
<air:BookingInfo BookingCode="N" CabinClass="Economy" FareInfoRef="J2GiU97Q2BKAMKe1AAAAAA==" SegmentRef="J2GiU97Q2BKA8Je1AAAAAA==" HostTokenRef="J2GiU97Q2BKAAKe1AAAAAA==" />
<air:TaxInfo Category="GB" Amount="USD99.80" Key="J2GiU97Q2BKACKe1AAAAAA==" />
<air:TaxInfo Category="UB" Amount="USD17.80" Key="J2GiU97Q2BKADKe1AAAAAA==" />
<air:TaxInfo Category="I2" Amount="USD5.20" Key="J2GiU97Q2BKAEKe1AAAAAA==" />
<air:TaxInfo Category="OM" Amount="USD5.20" Key="J2GiU97Q2BKAFKe1AAAAAA==" />
<air:TaxInfo Category="AE" Amount="USD20.40" Key="J2GiU97Q2BKAGKe1AAAAAA==" />
<air:TaxInfo Category="F6" Amount="USD9.50" Key="J2GiU97Q2BKAHKe1AAAAAA==" />
<air:TaxInfo Category="TP" Amount="USD1.40" Key="J2GiU97Q2BKAIKe1AAAAAA==" />
<air:TaxInfo Category="ZR" Amount="USD1.40" Key="J2GiU97Q2BKAJKe1AAAAAA==" />
<air:TaxInfo Category="YQ" Amount="USD193.00" Key="J2GiU97Q2BKAKKe1AAAAAA==" />
</air:AirPricingInfo>
我上面给出了xml,我的任务是从&#34; TaxInfo&#34;打印类别和金额。
我无法获得Taxinfo属性,例如Category和Amount
foreach ($Results->children('air', true) as $price) {
if (strcmp($price->getName(), 'AirPricingInfo') == 0) {
foreach($price->children('air', true) as $tax){
print_r($tax->TaxInfo);
}
}
}
答案 0 :(得分:0)
您可以使用foreach
循环$Results
并使用getName检查每个SimpleXMLElement的名称。
如果匹配,您可以从属性中获取Category
和Amount
。
例如:
$source = <<<SOURCE
<air:AirPricingInfo Key="J2GiU97Q2BKABKe1AAAAAA==" TotalPrice="USD663.70" BasePrice="GBP233.00" ApproximateTotalPrice="USD663.70" ApproximateBasePrice="USD310.00" EquivalentBasePrice="USD310.00" ApproximateTaxes="USD353.70" Taxes="USD353.70" LatestTicketingTime="2017-11-06T23:59:00.000-05:00" PricingMethod="Auto" Refundable="true" IncludesVAT="false" PlatingCarrier="WY" ProviderCode="1V">
<air:FareInfo Key="J2GiU97Q2BKALKe1AAAAAA==" FareBasis="NVE6MGB" PassengerTypeCode="ADT" Origin="MAN" Destination="DXB" EffectiveDate="2017-10-28T09:48:00.000-04:00" DepartureDate="2017-11-09" Amount="USD155.00" NotValidBefore="2017-11-09" NotValidAfter="2017-11-09" TaxAmount="USD220.70">
<air:FareRuleKey FareInfoRef="J2GiU97Q2BKALKe1AAAAAA==" ProviderCode="1V">6UUVoSldxwi3bYRYr8cIKsbKj3F8T9EyxsqPcXxP0TIjSPOlaHfQe5cuasWd6i8Dly5qxZ3qLwOXLmrFneovA5cuasWd6i8Dly5qxZ3qLwOXLmrFneovAxmyschz/qZvM3ExqSoG051W8N+Siiit9ZnGFThoE0iqQu0ZscBMSQ5d2/MbJh0jzdltclw4eGdWYibrzK0Ouv3G7OIYHTs6iRll6FxyIC6cYuAWfcH2w92IEQfz1U0L7yHdlLUXaJyB6STZDo2E3i3qkp0FEw0raOCbZ1nsUQQBLrDF4/ul0s6tkecSR34H+ouFsAExMoVlv4Xvb2u1Qx+/he9va7VDH7+F729rtUMfv4Xvb2u1Qx+/he9va7VDHzyxauAs+veBE308BFXsd7QPNqcmmS6r7B2WN4EjYakqaxRx0b5/L3T35IrCOmWUmvjyoufDRBrY5GwF8kqQiiA=</air:FareRuleKey>
</air:FareInfo>
<air:FareInfo Key="J2GiU97Q2BKAMKe1AAAAAA==" FareBasis="NVE6MGB" PassengerTypeCode="ADT" Origin="DXB" Destination="MAN" EffectiveDate="2017-10-28T09:48:00.000-04:00" DepartureDate="2017-11-16" Amount="USD155.00" NotValidBefore="2017-11-16" NotValidAfter="2017-11-16" TaxAmount="USD133.00">
<air:FareRuleKey FareInfoRef="J2GiU97Q2BKAMKe1AAAAAA==" ProviderCode="1V">6UUVoSldxwi3bYRYr8cIKsbKj3F8T9EyxsqPcXxP0TIjSPOlaHfQe5cuasWd6i8Dly5qxZ3qLwOXLmrFneovA5cuasWd6i8Dly5qxZ3qLwOXLmrFneovAxmyschz/qZvM3ExqSoG051cSlL+hx+N9VZDfT4YdB6B83f1UwCbb2Vd2/MbJh0jzdltclw4eGdWYibrzK0Ouv3SE6fqwbUqcRll6FxyIC6cYuAWfcH2w92IEQfz1U0L7yHdlLUXaJyB6STZDo2E3i3vWpSmZkrE0eCbZ1nsUQQB6KkuhxM2UfKtkecSR34H+ouFsAExMoVlv4Xvb2u1Qx+/he9va7VDH7+F729rtUMfv4Xvb2u1Qx+/he9va7VDHzyxauAs+veBE308BFXsd7QPNqcmmS6r7B2WN4EjYakqaxRx0b5/L3T35IrCOmWUmvjyoufDRBrY5GwF8kqQiiA=</air:FareRuleKey>
</air:FareInfo>
<air:BookingInfo BookingCode="N" CabinClass="Economy" FareInfoRef="J2GiU97Q2BKALKe1AAAAAA==" SegmentRef="J2GiU97Q2BKA2Je1AAAAAA==" HostTokenRef="J2GiU97Q2BKA/Je1AAAAAA==" />
<air:BookingInfo BookingCode="N" CabinClass="Economy" FareInfoRef="J2GiU97Q2BKALKe1AAAAAA==" SegmentRef="J2GiU97Q2BKA4Je1AAAAAA==" HostTokenRef="J2GiU97Q2BKA/Je1AAAAAA==" />
<air:BookingInfo BookingCode="N" CabinClass="Economy" FareInfoRef="J2GiU97Q2BKAMKe1AAAAAA==" SegmentRef="J2GiU97Q2BKA6Je1AAAAAA==" HostTokenRef="J2GiU97Q2BKAAKe1AAAAAA==" />
<air:BookingInfo BookingCode="N" CabinClass="Economy" FareInfoRef="J2GiU97Q2BKAMKe1AAAAAA==" SegmentRef="J2GiU97Q2BKA8Je1AAAAAA==" HostTokenRef="J2GiU97Q2BKAAKe1AAAAAA==" />
<air:TaxInfo Category="GB" Amount="USD99.80" Key="J2GiU97Q2BKACKe1AAAAAA==" />
<air:TaxInfo Category="UB" Amount="USD17.80" Key="J2GiU97Q2BKADKe1AAAAAA==" />
<air:TaxInfo Category="I2" Amount="USD5.20" Key="J2GiU97Q2BKAEKe1AAAAAA==" />
<air:TaxInfo Category="OM" Amount="USD5.20" Key="J2GiU97Q2BKAFKe1AAAAAA==" />
<air:TaxInfo Category="AE" Amount="USD20.40" Key="J2GiU97Q2BKAGKe1AAAAAA==" />
<air:TaxInfo Category="F6" Amount="USD9.50" Key="J2GiU97Q2BKAHKe1AAAAAA==" />
<air:TaxInfo Category="TP" Amount="USD1.40" Key="J2GiU97Q2BKAIKe1AAAAAA==" />
<air:TaxInfo Category="ZR" Amount="USD1.40" Key="J2GiU97Q2BKAJKe1AAAAAA==" />
<air:TaxInfo Category="YQ" Amount="USD193.00" Key="J2GiU97Q2BKAKKe1AAAAAA==" />
</air:AirPricingInfo>
SOURCE;
$Results = simplexml_load_string($source);
foreach($Results as $elm) {
if ($elm->getName() === "air:TaxInfo") {
$category = (string)$elm->attributes()->Category;
$amount = (string)$elm->attributes()->Amount;
echo $category, " ", $amount, PHP_EOL;
}
}
将导致:
GB USD99.80
UB USD17.80
I2 USD5.20
OM USD5.20
AE USD20.40
F6 USD9.50
TP USD1.40
ZR USD1.40
YQ USD193.00