I'm writing a shipping module that requests rates from FedEx etc. I'm able to retrieve FedEx's XML rate response, and now I'm parsing through it to get the rates. Is looping through the children the only way to examine the results? This is not fun
For example here's a much-shortened and simplified XML blurb. Basically there's some misc info toward the top, and then a bunch of `RateReplyDetails` tags, each with a method and a price, among many other things that I won't need.
And I'm parsing that like so:
For starters, I'd love it if I could simply check `l.parsedResponse:RateReply:HighestSeverity` to see if the request was a success or not, but it doesn't seem like I can. Both of these attempts come up empty:
It seems like my only option is to loop through children, find the one I want by name, then loop through it's children, find the next one, and so on. I have a ridiculous nested foreach that's just going to get worse as I dig deeper into the XML.
Is this how it's done in Mivascript, or am I missing something totally obvious?
For example here's a much-shortened and simplified XML blurb. Basically there's some misc info toward the top, and then a bunch of `RateReplyDetails` tags, each with a method and a price, among many other things that I won't need.
HTML Code:
<?xml version="1.0" encoding="UTF-8"?> <RateReply xmlns="http://fedex.com/ws/rate/v28"> <HighestSeverity>SUCCESS</HighestSeverity> <RateReplyDetails> <ServiceType>FIRST_OVERNIGHT</ServiceType> <ServiceDescription></ServiceDescription> <PackagingType>YOUR_PACKAGING</PackagingType> <SignatureOption>SERVICE_DEFAULT</SignatureOption> <RatedShipmentDetails> <ShipmentRateDetail> <TotalBaseCharge> <Currency>USD</Currency> <Amount>230.92</Amount> </TotalBaseCharge> <TotalFreightDiscounts> <Currency>USD</Currency> <Amount>0.0</Amount> </TotalFreightDiscounts> <TotalNetFreight> ... </TotalNetFreight> <TotalSurcharges> ... </TotalSurcharges> <TotalNetFedExCharge> <Currency>USD</Currency> <Amount>284.04</Amount> </TotalNetFedExCharge> <TotalTaxes> ... </TotalTaxes> <TotalNetCharge> ... </TotalNetCharge> <TotalRebates> ... </TotalRebates> <TotalDutiesAndTaxes> ... </TotalDutiesAndTaxes> <TotalAncillaryFeesAndTaxes> ... </TotalAncillaryFeesAndTaxes> <TotalDutiesTaxesAndFees> ... </TotalDutiesTaxesAndFees> <TotalNetChargeWithDutiesAndTaxes> <Currency>USD</Currency> <Amount>284.04</Amount> </TotalNetChargeWithDutiesAndTaxes> <Surcharges> <SurchargeType>FUEL</SurchargeType> <Description>Fuel</Description> <Amount> <Currency>USD</Currency> <Amount>53.12</Amount> </Amount> </Surcharges> </ShipmentRateDetail> </RatedShipmentDetails> </RateReplyDetails> <RateReplyDetails> ... </RateReplyDetails> <RateReplyDetails> ... </RateReplyDetails> <RateReplyDetails> ... </RateReplyDetails> </RateReply>
Code:
<mvAssign name="l.parseSuccessful" value="{xml_parse_var( l.response, l.parsedResponse )}">
Code:
<br>test 1:<br> <mvEval expr="{l.parsedResponse:RateReply:HighestSeverity} "> <br>test 2:<br> <mvEval expr="{l.parsedResponse:RateReply:HighestSeverity:value}">
Code:
<mvForEach array="l.parsedResponse:RateReply:Children" iterator="l.childA"> <mvIf expr="{l.childA:name EQ 'RateReplyDetails'}"> <mvForEach array="l.childA:Children" iterator="l.childB"> <mvIf expr="{l.childB:name EQ 'RatedShipmentDetails'}"> <mvForEach array="l.childB:Children" iterator="l.childC"> <mvIf expr="{l.childC:name EQ 'ShipmentRateDetail'}"> kill me now </mvIf> </mvForEach> </mvIf> </mvForEach> </mvIf> </mvForEach>
Comment