Skip to main content
Published: January 05 2012, 5:39:00 PMUpdated: November 28 2020, 10:11:14 PM


  You can use the JAXB Unmarshaller interface to inflate an XML document into a java object or to deserialize java objects from xml.   This sample illustrates the use of JAVA JAXB framework to unzip the file returned in downloadFile API 
 and unmarshal the Merchant Data xml document that based on Merchant Data Schema.

  To run this program, you will need to first generate java classes that represent the Marchant Data Schema.  Pleaes refer to the construct LMS data files with eBay Merchant Data Schema in JAVA kb for the codeGen ant script for the same.

 Also, you can check the attached Java source code for the implementation of the BulkDataExchangeResponse xml for ReviseFixedPriceItem call.

import ebay.apis.eblbasecomponents.BulkDataExchangeResponsesType;
import ebay.apis.eblbasecomponents.ExternalTransactionType;
import ebay.apis.eblbasecomponents.OrderDetailsType;
import ebay.apis.eblbasecomponents.SoldReportResponseType;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Unmarshaller;

public class SoldReport{

    private static String jaxb_object_tree_package_name = "ebay.apis.eblbasecomponents";
    private static String destinationPathForUnzipped = "C:\\tmp\\unzipped\\";

    public static void main(String[] args) {

        String soldReportFilePath="c:\\5024432353_report.gz";
        BulkDataExchangeResponsesType bd = (BulkDataExchangeResponsesType)readResponse(soldReportFilePath);
         SoldReportResponseType soldreport = bd.getSoldReport();

            List<OrderDetailsType> list = soldreport.getOrderDetails();
            for (OrderDetailsType details : list) {


    public static BulkDataExchangeResponsesType readResponse(String downloadZipFileName) {
        BulkDataExchangeResponsesType bd = null;
        Object obj = null;
        try {
            String unzippedFile = getZipFiles(downloadZipFileName,destinationPathForUnzipped);
            JAXBContext jc = JAXBContext.newInstance(jaxb_object_tree_package_name);
            // create an Unmarshaller
            Unmarshaller u = jc.createUnmarshaller();
            JAXBElement<Object> poe = (JAXBElement) u.unmarshal(new FileInputStream(unzippedFile));
            obj = poe.getValue();
            bd = (BulkDataExchangeResponsesType) obj;

        } catch (Exception e) {
        return bd;

  public static String getZipFiles(String filename , String destinationPath )
         String unzippedEntryName=null;

            byte[] buf = new byte[1024];
            ZipInputStream zipinputstream = null;
            ZipEntry zipentry;
            zipinputstream = new ZipInputStream(
                new FileInputStream(filename));

            zipentry = zipinputstream.getNextEntry();

            while (zipentry != null)
                //for each entry to be extracted
                unzippedEntryName = zipentry.getName();
                System.out.println("entryname "+unzippedEntryName);

                int n;
                FileOutputStream fileoutputstream;
                File newFile = new File(unzippedEntryName);
                String directory = newFile.getParent();
                if(directory == null)

                fileoutputstream = new FileOutputStream(

                while ((n =, 0, 1024)) > -1)
                    fileoutputstream.write(buf, 0, n);

                zipentry = zipinputstream.getNextEntry();


        catch (Exception e)
        return destinationPath+ unzippedEntryName;


How well did this answer your question?
Answers others found helpful