2

i am trying to read the response generated from ebay api.Response is

if i am reading the value of

Ack

tag it is fine. but if i am reading the value of

ItemID

it is givin null;

<?xml version="1.0" encoding="UTF-8"?>
<AddItemResponse xmlns="urn:ebay:apis:eBLBaseComponents">
   <Timestamp>2015-09-02T12:18:20.267Z</Timestamp>
   <Ack>Warning</Ack>
   <Errors>
      <ShortMessage>Listing may violate the Duplicate Listing policy.</ShortMessage>
      <LongMessage>This listing may be identical to test5 (110167922580). Under our duplicate listing policy, it may not be shown to buyers. When the identical listing receives a bid, this listing will be shown to buyers. If the items you want to sell are not identical, revise your listings to make the differences more obvious.</LongMessage>
      <ErrorCode>21917239</ErrorCode>
      <SeverityCode>Warning</SeverityCode>
      <ErrorParameters ParamID="0">
         <Value>test5</Value>
      </ErrorParameters>
      <ErrorParameters ParamID="1">
         <Value>110167922580</Value>
      </ErrorParameters>
      <ErrorClassification>RequestError</ErrorClassification>
   </Errors>
   <Version>931</Version>
   <Build>E931_UNI_API5_17617533_R1</Build>
   <ItemID>110167925316</ItemID>
   <StartTime>2015-09-02T12:18:19.783Z</StartTime>
   <EndTime>2015-09-09T12:18:19.783Z</EndTime>
   <Fees>
      <Fee>
         <Name>AuctionLengthFee</Name>
         <Fee currencyID="USD">0.0</Fee>
      </Fee>
      <Fee>
         <Name>BoldFee</Name>
         <Fee currencyID="USD">0.0</Fee>
      </Fee>
      <Fee>
         <Name>BuyItNowFee</Name>
         <Fee currencyID="USD">0.0</Fee>
      </Fee>
      <Fee>
         <Name>CategoryFeaturedFee</Name>
         <Fee currencyID="USD">0.0</Fee>
      </Fee>
      <Fee>
         <Name>FeaturedFee</Name>
         <Fee currencyID="USD">0.0</Fee>
      </Fee>
      <Fee>
         <Name>GalleryPlusFee</Name>
         <Fee currencyID="USD">0.0</Fee>
      </Fee>
      <Fee>

what i have written to read the xml is :

 public String readXMLResponse(XmlStreamReader reader, String sxmltag)
  {
    string retValue;
    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;
  }

and trying to find the value by :--

result = readXMLResponse(reader,'Ack');
result2 = readXMLResponse(reader,'ItemID');

result2 is null however response xml have value within this tag. please help.

Update

public String readXMLResponse(XmlStreamReader reader, String sxmltag)
  {
    string retValue;
    while(reader.hasNext()) {
      if (reader.getEventType() == XmlTag.START_ELEMENT) {
        if (reader.getLocalName()== sxmltag) {
          reader.next();              
          if (reader.getEventType() == XmlTag.characters) {
            retValue = reader.getText();
           system.debug('within readresponse1'+retValue);
          }
        }
      }
      reader.next();
    }
    return retValue;
  }

Thanks in advance..

4
  • 1
    use system.debug statements and print what's happening in ur while loop and see if the if statements is getting executed or not and what element / event type you need to parse.. Sep 2, 2015 at 13:07
  • Thanks for your response.if i am adding debug statement it is giving within readresponse1null and within readresponse2 Success.above is the edited code. Sep 2, 2015 at 13:20
  • 1
    I don't know if you've included all of your xml or not, but I don't see a closing tag that matches your first tag <Fees>, instead I see what appears to be an extra <Fee> which could be the source of your problem.
    – crmprogdev
    Sep 2, 2015 at 14:05
  • 2
    Assuming your XML is valid, your code would be cleaner if you just dumped all the XML into a DOM using Dom.Document.load so you could then use the Dom.XmlNode methods to pick out the values you want.
    – Keith C
    Sep 2, 2015 at 15:32

0

You must log in to answer this question.

Browse other questions tagged .