function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
osamanosaman 

Reading an attribute value from XML using XmlStreamReader

I want to read a particular value from XML using the XmlStreamReader class.

 

for (Integer i = 0; i < reader.getAttributeCount(); i ++) {
     if (reader.getAttributeLocalName(i).equals('chapter')) {
         value = reader.getAttributeValueAt(i);
     }     
}

 

 

does this code work? any can who has done this before guide me??

 

Thanks 

BritishBoyinDCBritishBoyinDC

If you pass in the xml and a tag as a string likes this to the function below, it returns the results for that tag:

 

 

//Previous code calls webservice etc.. reader = res.getXmlStreamReader(); allclicks = readXMLResponse(reader,'clicks');

 

 

 

 

public static String readXMLResponse(XmlStreamReader reader, String sxmltag){ string retValue; // Read through the XML system.debug(reader.toString()); while(reader.hasNext()) { if (reader.getEventType() == XmlTag.START_ELEMENT) { if (reader.getLocalName() == sxmltag) { reader.next(); if (reader.getEventType() == XmlTag.characters) { retValue = reader.getText(); } } } reader.next(); } return retValue; }

 

 

 

osamanosaman

Thanks for the quick reply. I have something like this in the response..

 

<TotalNetRates>

    <Currency>USD</CURRENCY>

           <Amount>231.04</Amount>

</TotalNetRates>

 

I want to parse total net rates and display it. How do i do that? Do I have to parse each element or would it be done by parsing Total Net Rates only.

 

BritishBoyinDCBritishBoyinDC

That, I don't know, but I think you need to look here for more info on parsing XML:

 

http://developer.force.com/codeshare/apex/ProjectPage?id=a0630000002ahp5AAA

osamanosaman

reader = res.getXmlStreamReader();
allclicks = readXMLResponse(reader,'clicks');

 

 

If I follow this code, then what do I have to write at the place of 'Clicks'..TotalNetRates or Amount?

BritishBoyinDCBritishBoyinDC
If I understand your XML correctly, 'Amount' should return the value in the Amount tag
osamanosaman
But the problem is I have a long reply in which I have so many Amount tags but I want the TotalNetRate's one particularly.
BritishBoyinDCBritishBoyinDC
I would take a look at the apex docs where they discuss the XMLStreamReader Class - it explains in more detail how you can search for specific attributes and events in the XML code
prageethprageeth

I think following will help you. 

 

while (reader.hasNext()) {

  if (reader.getLocalName() == 'TotalNetRates' && reader.getEventType() == XmlTag.START_ELEMENT) {

    while (reader.hasNext()) {

      if (reader.getLocalName() == 'TotalNetRates' && reader.getEventType() == XmlTag.END_ELEMENT) {

        break;

      }

      while (reader.hasNext()) {

        if (reader.getLocalName() == 'Amount' && reader.getEventType() == XmlTag.START_ELEMENT) {

          while (reader.hasNext()) {

            if (reader.getLocalName() == 'Amount' && reader.getEventType() == XmlTag.END_ELEMENT) {

              break;

            }

            while (reader.hasNext()) {

              if (reader.getEventType() == XmlTag.CHARACTERS) {

                return reader.getText();

              }

              reader.next();

            }

            reader.next();

          }

        }

        reader.next();

      }

      reader.next();

    }

  }

  reader.next();

 

 

osamanosaman

I tried the above code but it did not work. But However I tried the below code something worked but still not getting the correct amount. I am getting another amount.

 

//Previous code calls webservice etc..

reader = res.getXmlStreamReader();
allclicks = readXMLResponse(reader,'clicks');

 

 

 

 

public static String readXMLResponse(XmlStreamReader reader, String sxmltag){
string retValue;
// Read through the XML
system.debug(reader.toString());
while(reader.hasNext()) {
if (reader.getEventType() == XmlTag.START_ELEMENT) {
if (reader.getLocalName() == sxmltag) {
reader.next();
if (reader.getEventType() == XmlTag.characters) {
retValue = reader.getText();
}
}
}
reader.next();
}
return retValue;
}

 

 

 

</v6:LocalizedMessage><v6:MessageParameters><v6:Id>ORIGIN_OR_DESTINATION</v6:Id><v6:Value>origin</v6:Value></v6:MessageParameters></v6:Notifications><v6:Version><v6:ServiceId>crs</v6:ServiceId><v6:Major>6</v6:Major><v6:Intermediate>0</v6:Intermediate><v6:Minor>0</v6:Minor></v6:Version><v6:RateReplyDetails><v6:ServiceType>INTERNATIONAL_PRIORITY</v6:ServiceType><v6:PackagingType>YOUR_PACKAGING</v6:PackagingType><v6:DestinationAirportId>DXB</v6:DestinationAirportId><v6:IneligibleForMoneyBackGuarantee>false</v6:IneligibleForMoneyBackGuarantee><v6:OriginServiceArea>PM</v6:OriginServiceArea><v6:DestinationServiceArea>PM</v6:DestinationServiceArea><v6:SignatureOption>SERVICE_DEFAULT</v6:SignatureOption><v6:ActualRateType>PAYOR_ACCOUNT</v6:ActualRateType><v6:RatedShipmentDetails><v6:ShipmentRateDetail><v6:RateType>PAYOR_ACCOUNT</v6:RateType><v6:RateScale>0000001</v6:RateScale><v6:RateZone>PK001O</v6:RateZone><v6:PricingCode>ACTUAL</v6:PricingCode><v6:CurrencyExchangeRate><v6:FromCurrency>USD</v6:FromCurrency><v6:IntoCurrency>WON</v6:IntoCurrency><v6:Rate>1201.12</v6:Rate></v6:CurrencyExchangeRate><v6:DimDivisor>166</v6:DimDivisor><v6:FuelSurchargePercent>12.5</v6:FuelSurchargePercent><v6:TotalBillingWeight><v6:Units>KG</v6:Units><v6:Value>2.0</v6:Value></v6:TotalBillingWeight><v6:TotalBaseCharge><v6:Currency>WON</v6:Currency><v6:Amount>163300.0</v6:Amount></v6:TotalBaseCharge><v6:TotalFreightDiscounts><v6:Currency>WON</v6:Currency><v6:Amount>16330.0</v6:Amount></v6:TotalFreightDiscounts><v6:TotalNetFreight><v6:Currency>WON</v6:Currency><v6:Amount>146970.0</v6:Amount></v6:TotalNetFreight><v6:TotalSurcharges><v6:Currency>WON</v6:Currency><v6:Amount>18380.0</v6:Amount></v6:TotalSurcharges><v6:TotalNetFedExCharge><v6:Currency>WON</v6:Currency><v6:Amount>165350.0</v6:Amount></v6:TotalNetFedExCharge><v6:TotalTaxes><v6:Currency>WON</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalTaxes><v6:TotalNetCharge><v6:Currency>WON</v6:Currency><v6:Amount>165350.0</v6:Amount></v6:TotalNetCharge><v6:TotalRebates><v6:Currency>WON</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalRebates><v6:FreightDiscounts><v6:RateDiscountType>VOLUME</v6:RateDiscountType><v6:Description>Volume</v6:Description><v6:Amount><v6:Currency>WON</v6:Currency><v6:Amount>16330.0</v6:Amount></v6:Amount><v6:Percent>10.0</v6:Percent></v6:FreightDiscounts><v6:Surcharges><v6:SurchargeType>FUEL</v6:SurchargeType><v6:Description>Fuel</v6:Description><v6:Amount><v6:Currency>WON</v6:Currency><v6:Amount>18380.0</v6:Amount></v6:Amount></v6:Surcharges></v6:ShipmentRateDetail></v6:RatedShipmentDetails><v6:RatedShipmentDetails><v6:EffectiveNetDiscount><v6:Currency>USD</v6:Currency><v6:Amount>15.29</v6:Amount></v6:EffectiveNetDiscount><v6:ShipmentRateDetail><v6:RateType>RATED_ACCOUNT</v6:RateType><v6:RateScale>0000001</v6:RateScale><v6:RateZone>PK001O</v6:RateZone><v6:PricingCode>ACTUAL</v6:PricingCode><v6:CurrencyExchangeRate><v6:FromCurrency>USD</v6:FromCurrency><v6:IntoCurrency>USD</v6:IntoCurrency><v6:Rate>1.0</v6:Rate></v6:CurrencyExchangeRate><v6:DimDivisor>166</v6:DimDivisor><v6:FuelSurchargePercent>12.5</v6:FuelSurchargePercent><v6:TotalBillingWeight><v6:Units>KG</v6:Units><v6:Value>2.0</v6:Value></v6:TotalBillingWeight><v6:TotalBaseCharge><v6:Currency>USD</v6:Currency><v6:Amount>135.96</v6:Amount></v6:TotalBaseCharge><v6:TotalFreightDiscounts><v6:Currency>USD</v6:Currency><v6:Amount>13.59</v6:Amount></v6:TotalFreightDiscounts><v6:TotalNetFreight><v6:Currency>USD</v6:Currency><v6:Amount>122.37</v6:Amount></v6:TotalNetFreight><v6:TotalSurcharges><v6:Currency>USD</v6:Currency><v6:Amount>15.3</v6:Amount></v6:TotalSurcharges><v6:TotalNetFedExCharge><v6:Currency>USD</v6:Currency><v6:Amount>137.67</v6:Amount></v6:TotalNetFedExCharge><v6:TotalTaxes><v6:Currency>USD</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalTaxes><v6:TotalNetCharge><v6:Currency>USD</v6:Currency><v6:Amount>137.67</v6:Amount></v6:TotalNetCharge><v6:TotalRebates><v6:Currency>USD</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalRebates><v6:Surcharges><v6:SurchargeType>FUEL</v6:SurchargeType><v6:Description>Fuel</v6:Description><v6:Amount><v6:Currency>USD</v6:Currency><v6:Amount>15.3</v6:Amount></v6:Amount></v6:Surcharges></v6:ShipmentRateDetail></v6:RatedShipmentDetails><v6:RatedShipmentDetails><v6:ShipmentRateDetail><v6:RateType>PAYOR_LIST</v6:RateType><v6:RateScale>0000000</v6:RateScale><v6:RateZone>PK001O</v6:RateZone><v6:PricingCode>ACTUAL</v6:PricingCode><v6:CurrencyExchangeRate><v6:FromCurrency>USD</v6:FromCurrency><v6:IntoCurrency>USD</v6:IntoCurrency><v6:Rate>1.0</v6:Rate></v6:CurrencyExchangeRate><v6:DimDivisor>166</v6:DimDivisor><v6:FuelSurchargePercent>12.5</v6:FuelSurchargePercent><v6:TotalBillingWeight><v6:Units>KG</v6:Units><v6:Value>2.0</v6:Value></v6:TotalBillingWeight><v6:TotalBaseCharge><v6:Currency>USD</v6:Currency><v6:Amount>135.96</v6:Amount></v6:TotalBaseCharge><v6:TotalFreightDiscounts><v6:Currency>USD</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalFreightDiscounts><v6:TotalNetFreight><v6:Currency>USD</v6:Currency><v6:Amount>135.96</v6:Amount></v6:TotalNetFreight><v6:TotalSurcharges><v6:Currency>USD</v6:Currency><v6:Amount>17.0</v6:Amount></v6:TotalSurcharges><v6:TotalNetFedExCharge><v6:Currency>USD</v6:Currency><v6:Amount>152.96</v6:Amount></v6:TotalNetFedExCharge><v6:TotalTaxes><v6:Currency>USD</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalTaxes><v6:TotalNetCharge><v6:Currency>USD</v6:Currency><v6:Amount>152.96</v6:Amount></v6:TotalNetCharge><v6:TotalRebates><v6:Currency>USD</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalRebates><v6:Surcharges><v6:SurchargeType>FUEL</v6:SurchargeType><v6:Description>Fuel</v6:Description><v6:Amount><v6:Currency>USD</v6:Currency><v6:Amount>17.0</v6:Amount></v6:Amount></v6:Surcharges></v6:ShipmentRateDetail></v6:RatedShipmentDetails><v6:RatedShipmentDetails><v6:ShipmentRateDetail><v6:RateType>RATED_LIST</v6:RateType><v6:RateScale>0000000</v6:RateScale><v6:RateZone>PK001O</v6:RateZone><v6:PricingCode>ACTUAL</v6:PricingCode><v6:CurrencyExchangeRate><v6:FromCurrency>USD</v6:FromCurrency><v6:IntoCurrency>USD</v6:IntoCurrency><v6:Rate>1.0</v6:Rate></v6:CurrencyExchangeRate><v6:DimDivisor>166</v6:DimDivisor><v6:FuelSurchargePercent>12.5</v6:FuelSurchargePercent><v6:TotalBillingWeight><v6:Units>KG</v6:Units><v6:Value>2.0</v6:Value></v6:TotalBillingWeight><v6:TotalBaseCharge><v6:Currency>USD</v6:Currency><v6:Amount>135.96</v6:Amount></v6:TotalBaseCharge><v6:TotalFreightDiscounts><v6:Currency>USD</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalFreightDiscounts><v6:TotalNetFreight><v6:Currency>USD</v6:Currency><v6:Amount>135.96</v6:Amount></v6:TotalNetFreight><v6:TotalSurcharges><v6:Currency>USD</v6:Currency><v6:Amount>17.0</v6:Amount></v6:TotalSurcharges><v6:TotalNetFedExCharge><v6:Currency>USD</v6:Currency><v6:Amount>152.96</v6:Amount></v6:TotalNetFedExCharge><v6:TotalTaxes><v6:Currency>USD</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalTaxes><v6:TotalNetCharge><v6:Currency>USD</v6:Currency><v6:Amount>152.96</v6:Amount></v6:TotalNetCharge><v6:TotalRebates><v6:Currency>USD</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalRebates><v6:Surcharges><v6:SurchargeType>FUEL</v6:SurchargeType><v6:Description>Fuel</v6:Description><v6:Amount><v6:Currency>USD</v6:Currency><v6:Amount>17.0</v6:Amount></v6:Amount></v6:Surcharges></v6:ShipmentRateDetail></v6:RatedShipmentDetails></v6:RateReplyDetails></v6:RateReply></soapenv:Body></soapenv:Envelope>

osamanosaman

here is my XML response

 

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/><soapenv:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><v6:RateReply xmlns:v6="http://fedex.com/ws/rate/v6"><v6:HighestSeverity>NOTE</v6:HighestSeverity><v6:Notifications><v6:Severity>NOTE</v6:Severity><v6:Source>crs</v6:Source><v6:Code>825</v6:Code><v6:Message>The routing code was derived from the city for the destination. </v6:Message><v6:LocalizedMessage>The routing code was derived from the city for the destination. </v6:LocalizedMessage><v6:MessageParameters><v6:Id>ORIGIN_OR_DESTINATION</v6:Id><v6:Value>destination</v6:Value></v6:MessageParameters></v6:Notifications><v6:Notifications><v6:Severity>NOTE</v6:Severity><v6:Source>crs</v6:Source><v6:Code>825</v6:Code><v6:Message>The routing code was derived from the city for the origin. </v6:Message><v6:LocalizedMessage>The routing code was derived from the city for the origin. </v6:LocalizedMessage><v6:MessageParameters><v6:Id>ORIGIN_OR_DESTINATION</v6:Id><v6:Value>origin</v6:Value></v6:MessageParameters></v6:Notifications><v6:Version><v6:ServiceId>crs</v6:ServiceId><v6:Major>6</v6:Major><v6:Intermediate>0</v6:Intermediate><v6:Minor>0</v6:Minor></v6:Version><v6:RateReplyDetails><v6:ServiceType>INTERNATIONAL_PRIORITY</v6:ServiceType><v6:PackagingType>YOUR_PACKAGING</v6:PackagingType><v6:DestinationAirportId>DXB</v6:DestinationAirportId><v6:IneligibleForMoneyBackGuarantee>false</v6:IneligibleForMoneyBackGuarantee><v6:OriginServiceArea>PM</v6:OriginServiceArea><v6:DestinationServiceArea>PM</v6:DestinationServiceArea><v6:SignatureOption>SERVICE_DEFAULT</v6:SignatureOption><v6:ActualRateType>PAYOR_ACCOUNT</v6:ActualRateType><v6:RatedShipmentDetails><v6:ShipmentRateDetail><v6:RateType>PAYOR_ACCOUNT</v6:RateType><v6:RateScale>0000001</v6:RateScale><v6:RateZone>PK001O</v6:RateZone><v6:PricingCode>ACTUAL</v6:PricingCode><v6:CurrencyExchangeRate><v6:FromCurrency>USD</v6:FromCurrency><v6:IntoCurrency>WON</v6:IntoCurrency><v6:Rate>1201.12</v6:Rate></v6:CurrencyExchangeRate><v6:DimDivisor>166</v6:DimDivisor><v6:FuelSurchargePercent>12.5</v6:FuelSurchargePercent><v6:TotalBillingWeight><v6:Units>KG</v6:Units><v6:Value>2.0</v6:Value></v6:TotalBillingWeight><v6:TotalBaseCharge><v6:Currency>WON</v6:Currency><v6:Amount>163300.0</v6:Amount></v6:TotalBaseCharge><v6:TotalFreightDiscounts><v6:Currency>WON</v6:Currency><v6:Amount>16330.0</v6:Amount></v6:TotalFreightDiscounts><v6:TotalNetFreight><v6:Currency>WON</v6:Currency><v6:Amount>146970.0</v6:Amount></v6:TotalNetFreight><v6:TotalSurcharges><v6:Currency>WON</v6:Currency><v6:Amount>18380.0</v6:Amount></v6:TotalSurcharges><v6:TotalNetFedExCharge><v6:Currency>WON</v6:Currency><v6:Amount>165350.0</v6:Amount></v6:TotalNetFedExCharge><v6:TotalTaxes><v6:Currency>WON</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalTaxes><v6:TotalNetCharge><v6:Currency>WON</v6:Currency><v6:Amount>165350.0</v6:Amount></v6:TotalNetCharge><v6:TotalRebates><v6:Currency>WON</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalRebates><v6:FreightDiscounts><v6:RateDiscountType>VOLUME</v6:RateDiscountType><v6:Description>Volume</v6:Description><v6:Amount><v6:Currency>WON</v6:Currency><v6:Amount>16330.0</v6:Amount></v6:Amount><v6:Percent>10.0</v6:Percent></v6:FreightDiscounts><v6:Surcharges><v6:SurchargeType>FUEL</v6:SurchargeType><v6:Description>Fuel</v6:Description><v6:Amount><v6:Currency>WON</v6:Currency><v6:Amount>18380.0</v6:Amount></v6:Amount></v6:Surcharges></v6:ShipmentRateDetail></v6:RatedShipmentDetails><v6:RatedShipmentDetails><v6:EffectiveNetDiscount><v6:Currency>USD</v6:Currency><v6:Amount>15.29</v6:Amount></v6:EffectiveNetDiscount><v6:ShipmentRateDetail><v6:RateType>RATED_ACCOUNT</v6:RateType><v6:RateScale>0000001</v6:RateScale><v6:RateZone>PK001O</v6:RateZone><v6:PricingCode>ACTUAL</v6:PricingCode><v6:CurrencyExchangeRate><v6:FromCurrency>USD</v6:FromCurrency><v6:IntoCurrency>USD</v6:IntoCurrency><v6:Rate>1.0</v6:Rate></v6:CurrencyExchangeRate><v6:DimDivisor>166</v6:DimDivisor><v6:FuelSurchargePercent>12.5</v6:FuelSurchargePercent><v6:TotalBillingWeight><v6:Units>KG</v6:Units><v6:Value>2.0</v6:Value></v6:TotalBillingWeight><v6:TotalBaseCharge><v6:Currency>USD</v6:Currency><v6:Amount>135.96</v6:Amount></v6:TotalBaseCharge><v6:TotalFreightDiscounts><v6:Currency>USD</v6:Currency><v6:Amount>13.59</v6:Amount></v6:TotalFreightDiscounts><v6:TotalNetFreight><v6:Currency>USD</v6:Currency><v6:Amount>122.37</v6:Amount></v6:TotalNetFreight><v6:TotalSurcharges><v6:Currency>USD</v6:Currency><v6:Amount>15.3</v6:Amount></v6:TotalSurcharges><v6:TotalNetFedExCharge><v6:Currency>USD</v6:Currency><v6:Amount>137.67</v6:Amount></v6:TotalNetFedExCharge><v6:TotalTaxes><v6:Currency>USD</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalTaxes><v6:TotalNetCharge><v6:Currency>USD</v6:Currency><v6:Amount>137.67</v6:Amount></v6:TotalNetCharge><v6:TotalRebates><v6:Currency>USD</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalRebates><v6:Surcharges><v6:SurchargeType>FUEL</v6:SurchargeType><v6:Description>Fuel</v6:Description><v6:Amount><v6:Currency>USD</v6:Currency><v6:Amount>15.3</v6:Amount></v6:Amount></v6:Surcharges></v6:ShipmentRateDetail></v6:RatedShipmentDetails><v6:RatedShipmentDetails><v6:ShipmentRateDetail><v6:RateType>PAYOR_LIST</v6:RateType><v6:RateScale>0000000</v6:RateScale><v6:RateZone>PK001O</v6:RateZone><v6:PricingCode>ACTUAL</v6:PricingCode><v6:CurrencyExchangeRate><v6:FromCurrency>USD</v6:FromCurrency><v6:IntoCurrency>USD</v6:IntoCurrency><v6:Rate>1.0</v6:Rate></v6:CurrencyExchangeRate><v6:DimDivisor>166</v6:DimDivisor><v6:FuelSurchargePercent>12.5</v6:FuelSurchargePercent><v6:TotalBillingWeight><v6:Units>KG</v6:Units><v6:Value>2.0</v6:Value></v6:TotalBillingWeight><v6:TotalBaseCharge><v6:Currency>USD</v6:Currency><v6:Amount>135.96</v6:Amount></v6:TotalBaseCharge><v6:TotalFreightDiscounts><v6:Currency>USD</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalFreightDiscounts><v6:TotalNetFreight><v6:Currency>USD</v6:Currency><v6:Amount>135.96</v6:Amount></v6:TotalNetFreight><v6:TotalSurcharges><v6:Currency>USD</v6:Currency><v6:Amount>17.0</v6:Amount></v6:TotalSurcharges><v6:TotalNetFedExCharge><v6:Currency>USD</v6:Currency><v6:Amount>152.96</v6:Amount></v6:TotalNetFedExCharge><v6:TotalTaxes><v6:Currency>USD</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalTaxes><v6:TotalNetCharge><v6:Currency>USD</v6:Currency><v6:Amount>152.96</v6:Amount></v6:TotalNetCharge><v6:TotalRebates><v6:Currency>USD</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalRebates><v6:Surcharges><v6:SurchargeType>FUEL</v6:SurchargeType><v6:Description>Fuel</v6:Description><v6:Amount><v6:Currency>USD</v6:Currency><v6:Amount>17.0</v6:Amount></v6:Amount></v6:Surcharges></v6:ShipmentRateDetail></v6:RatedShipmentDetails><v6:RatedShipmentDetails><v6:ShipmentRateDetail><v6:RateType>RATED_LIST</v6:RateType><v6:RateScale>0000000</v6:RateScale><v6:RateZone>PK001O</v6:RateZone><v6:PricingCode>ACTUAL</v6:PricingCode><v6:CurrencyExchangeRate><v6:FromCurrency>USD</v6:FromCurrency><v6:IntoCurrency>USD</v6:IntoCurrency><v6:Rate>1.0</v6:Rate></v6:CurrencyExchangeRate><v6:DimDivisor>166</v6:DimDivisor><v6:FuelSurchargePercent>12.5</v6:FuelSurchargePercent><v6:TotalBillingWeight><v6:Units>KG</v6:Units><v6:Value>2.0</v6:Value></v6:TotalBillingWeight><v6:TotalBaseCharge><v6:Currency>USD</v6:Currency><v6:Amount>135.96</v6:Amount></v6:TotalBaseCharge><v6:TotalFreightDiscounts><v6:Currency>USD</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalFreightDiscounts><v6:TotalNetFreight><v6:Currency>USD</v6:Currency><v6:Amount>135.96</v6:Amount></v6:TotalNetFreight><v6:TotalSurcharges><v6:Currency>USD</v6:Currency><v6:Amount>17.0</v6:Amount></v6:TotalSurcharges><v6:TotalNetFedExCharge><v6:Currency>USD</v6:Currency><v6:Amount>152.96</v6:Amount></v6:TotalNetFedExCharge><v6:TotalTaxes><v6:Currency>USD</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalTaxes><v6:TotalNetCharge><v6:Currency>USD</v6:Currency><v6:Amount>152.96</v6:Amount></v6:TotalNetCharge><v6:TotalRebates><v6:Currency>USD</v6:Currency><v6:Amount>0.0</v6:Amount></v6:TotalRebates><v6:Surcharges><v6:SurchargeType>FUEL</v6:SurchargeType><v6:Description>Fuel</v6:Description><v6:Amount><v6:Currency>USD</v6:Currency><v6:Amount>17.0</v6:Amount></v6:Amount></v6:Surcharges></v6:ShipmentRateDetail></v6:RatedShipmentDetails></v6:RateReplyDetails></v6:RateReply></soapenv:Body></soapenv:Envelope>

BritishBoyinDCBritishBoyinDC

I can't actually see TotalNetRate in this xml?

 

Either way, the only way I know how to do this is to loop through the xml and system.debug each element so that you can work out what elements/attributes you are looking for - in my example, I just needed to find the clicks attribute, but I think you need to find that attribute, and then loop through until you find the correct attribute that refers to the amount you want...

osamanosaman

Well I have done it by reading the xml in string and then find the required attribute. Its pretty odd but its working fine :)

 

Thanks anyway!

 

btw that was TotalNetFedexCharge actually. total net charge was just for sample.

BritishBoyinDCBritishBoyinDC
Ah, whatever works I say!
ThomasTTThomasTT

If you don't care SAX or DOM, here is a very very useful Code Share class XMLDom. It's from the "Ron Hess".

 

 http://developer.force.com/codeshare/apex/ProjectPage?id=a0630000002ahp5AAA

 

It's using XMLStreamReader inside it, but it provides DOM base access to the XML. So, you can get the Attribute by

element.getAttribute(String name)

and get node value (of the first matching child node) by

element.getValue(String name).

Without this, I can't use HttpRequest for SOAP Web Service (sometimes, WSDL2Apex doesn't work and I have to use HttpRequest  and read the SOAP message by myself or some web service which sends the data as anytype).

Thanks Ron!

 

ThomasTT

 

 

Message Edited by ThomasTT on 10-07-2009 03:49 PM
osamanosaman

I did see XmlDOM class..Can you elaborate further on how to use the class actually.

 

Thanks

ThomasTTThomasTT

Just read the test class XMLDomTest. That's how you learn how to use given programs.

 

ThomasTT