简体   繁体   中英

Deserializing XML String from Web Service API into C# Object

I am a novice-intermediate level programmer trying to take over a project for someone who left our team with no notice. I am really hoping someone here can illuminate the way here as to what I am doing wrong. I believe it has to do with the XML structure and how it is defined.

The problem RECAPPED: I am attempting to read an XML from our logistics system's database and convert it into a C# object. I am entering the database via a Web service API that returns the XML file in question as a string. I am getting that far with no issues, however, when I deserialize the XML string to an object I am getting nothing but blank/null elements on the resulting object.

XSD File: The XML file itself is very complex, so here is a link to the XSD for this file: https://www.magaya.com/XMLSchemas/V1/Shipment.xsd .

XML String is below inside the code block. It's very large to make sure to scroll all the way to the right to copy properly.

Here is my C# code that I am using to try and deserialize it into an object. Please excuse the sloppiness, it has been rough working through this issue.

C# code that deserializes:

    public static ShipmentType GetShipmentObject(string shipmentXML)
        { // Method to deserialize shipment XML into a C# object...
             ShipmentType ShipmentObject = null;
           try
            {
                if (!string.IsNullOrWhiteSpace(shipmentXML))
                {
                    using (TextReader reader = new StringReader(shipmentXML))
                    {
                        XmlRootAttribute xr = new XmlRootAttribute();
                        xr.Namespace = "http://www.magaya.com/XMLSchema/V1";
                        xr.ElementName = "Shipments";
                        xr.DataType = "OceanShipment";
                        //xr.IsNullable = false;
                        XmlSerializer deserializer = new XmlSerializer(typeof(ShipmentType),xr);
                        ShipmentObject = (ShipmentType)deserializer.Deserialize(reader);
                        return ShipmentObject;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                //LOGManager.LogFatal(ex, ex.Message);
            }
            return ShipmentObject;   
        }

Below is the XML string that this class returns. It is directly from Visual Studio's Debugger. It is THIS string that will not deserialize. I replaced some of the values to preserve privacy, but no other xml structure changes are present. I apologize for the length, everything below is ONLY the xml string so this is technically the end of my post here --->>

<?xml version="1.0" encoding="utf-8"?>
<Shipments xmlns="http://www.magaya.com/XMLSchema/V1">
  <OceanShipment GUID="99" Type="SH">
    <CreatedOn>2019-12-26T16:29:59-05:00</CreatedOn>
    <Number>EWL24195</Number>
    <CreatedByName>Madison Fernandez</CreatedByName>
    <Version>106</Version>
    <ModeOfTransportation Code="11">
      <Description>FCL-DOOR</Description>
      <Method>Ocean</Method>
    </ModeOfTransportation>
    <ModeOfTransportCode>11</ModeOfTransportCode>
    <IssuedByName>KS Co. LTD</IssuedByName>
    <IssuedBy GUID="35b740a3-7e4b-45e8-9e69-d3c9ea9d4fb8">
      <Type>ForwardingAgent</Type>
      <Name>KS Co. LTD</Name>
      <CreatedOn>2019-08-28T15:35:19-05:00</CreatedOn>
      <Address>
        <Street>99</Street>
        <City>city test</City>
        <State>state test</State>
        <ZipCode>99</ZipCode>
        <Country Code="CN">CN</Country>
        <Description>Default Shipping Address</Description>
      </Address>
      <BillingAddress>
        <Street>99</Street>
        <City>city test</City>
        <State>state test</State>
        <ZipCode>99</ZipCode>
        <Country Code="CN">CN</Country>
        <Description>Default Shipping Address</Description>
      </BillingAddress>
      <TransactionDueDays>10</TransactionDueDays>
      <PaymentTerms>
        <Description>Net 10</Description>
        <NetDueDays>10</NetDueDays>
        <DiscountPercentage>0.00</DiscountPercentage>
        <DiscountPaidDays>0</DiscountPaidDays>
      </PaymentTerms>
      <IsPrepaid>false</IsPrepaid>
    </IssuedBy>
    <IssuedByAddress>
      <Street>99</Street>
      <City>test</City>
      <State>test</State>
      <ZipCode>test</ZipCode>
      <Country Code="CN">CN</Country>
      <Description>Default Shipping Address</Description>
    </IssuedByAddress>
    <ShipperName>Standard Fiber</ShipperName>
    <Shipper GUID="999999">
      <Type>Vendor</Type>
      <Name>dummy shipper</Name>
      <CreatedOn>2012-07-02T18:36:53-05:00</CreatedOn>
      <Address>
        <Street>test</Street>
        <Street>test</Street>
        <City>Shanghai</City>
        <Country Code="CN">CN</Country>
        <Description>Default Shipping Address</Description>
      </Address>
      <BillingAddress>
        <Street>test</Street>
        <Street>test</Street>
        <City>Shanghai</City>
        <Country Code="CN">CN</Country>
        <Description>Default Billing Address</Description>
      </BillingAddress>
      <Phone>985818</Phone>
      <AccountNumber>13283</AccountNumber>
      <IsPrepaid>true</IsPrepaid>
    </Shipper>
    <ShipperAddress>
      <Street>test</Street>
      <Street>test</Street>
      <City>Shanghai</City>
      <Country Code="CN">CN</Country>
      <Description>Default Shipping Address</Description>
    </ShipperAddress>
    <ConsigneeName>Cnee</ConsigneeName>
    <Consignee GUID="186510fc-e1c4-4b8b-a0c4-99363b15bd41">
      <Type>Client</Type>
      <Name>Cnee</Name>
      <CreatedOn>2018-05-08T13:14:48-05:00</CreatedOn>
      <Address>
        <Street>TEST STREET NUMBER</Street>
        <City>Red Bank</City>
        <State>NJ</State>
        <ZipCode>07701</ZipCode>
        <Country Code="US">USA</Country>
        <Description>Default Shipping Address</Description>
      </Address>
      <BillingAddress>
        <Street>TEST STREET NUMBER</Street>
        <City>Red Bank</City>
        <State>NJ</State>
        <ZipCode>07701</ZipCode>
        <Country Code="US">USA</Country>
        <Description>Default Billing Address</Description>
      </BillingAddress>
      <AccountNumber>CX10136</AccountNumber>
      <Balance Currency="USD">114517.15998894054443</Balance>
      <TransactionDueDays>15</TransactionDueDays>
      <PaymentTerms>
        <Description>Net 15</Description>
        <NetDueDays>15</NetDueDays>
        <DiscountPercentage>0.00</DiscountPercentage>
        <DiscountPaidDays>0</DiscountPaidDays>
      </PaymentTerms>
      <IsPrepaid>false</IsPrepaid>
    </Consignee>
    <ConsigneeAddress>
      <Street>TEST STREET NUMBER</Street>
      <City>Red Bank</City>
      <State>NJ</State>
      <ZipCode>07701</ZipCode>
      <Country Code="US">USA</Country>
      <Description>Default Shipping Address</Description>
    </ConsigneeAddress>
    <DestinationAgentName>Empire Worldwide Logistics, LLC</DestinationAgentName>
    <DestinationAgent GUID="978d4f95-8183-4820-830e-a40dfc4cb3d3">
      <Type>ForwardingAgent</Type>
      <Name>Empire Worldwide Logistics, LLC</Name>
      <CreatedOn>2010-08-06T16:27:13-05:00</CreatedOn>
      <Address>
        <Street>360 North Sepulveda Blvd</Street>
        <Street>Suite 1054</Street>
        <City>EL Segundo</City>
        <State>CA</State>
        <ZipCode>90245</ZipCode>
        <Country Code="US">USA</Country>
        <Description>Default Shipping Address</Description>
        <ContactName>Kenneth Quartarolo</ContactName>
        <ContactPhone>424-239-6466</ContactPhone>
        <ContactEmail>dummy@empirewwl.com</ContactEmail>
      </Address>
      <BillingAddress>
        <Street>360 North Sepulveda Blvd</Street>
        <Street>Suite 1054</Street>
        <City>EL Segundo</City>
        <State>CA</State>
        <ZipCode>90245</ZipCode>
        <Country Code="US">USA</Country>
        <Description>Default Billing Address</Description>
        <ContactName>dummy contact</ContactName>
        <ContactPhone>424-239-6466</ContactPhone>
        <ContactEmail>dummy@empirewwl.com</ContactEmail>
      </BillingAddress>
      <Email>dummy@empirewwl.com</Email>
      <Website>empirewwl.com</Website>
      <Phone>424-239-6466</Phone>
      <ContactFirstName>Kenneth</ContactFirstName>
      <ContactLastName>Quartarolo</ContactLastName>
      <ExporterID>123</ExporterID>
      <ExporterIDType>EIN</ExporterIDType>
      <NetworkID>21849</NetworkID>
      <IsKnownShipper>true</IsKnownShipper>
      <IsPrepaid>true</IsPrepaid>
      <AgentInfo>
        <FMCNumber>022706N</FMCNumber>
        <SCACNumber>EWLL</SCACNumber>
      </AgentInfo>
    </DestinationAgent>
    <DestinationAgentAddress>
      <Street>360 North Sepulveda Blvd</Street>
      <Street>Suite 1054</Street>
      <City>EL Segundo</City>
      <State>CA</State>
      <ZipCode>90245</ZipCode>
      <Country Code="US">USA</Country>
      <Description>Default Shipping Address</Description>
      <ContactName>dummy contact</ContactName>
      <ContactPhone>424-239-6466</ContactPhone>
      <ContactEmail>dummy@empirewwl.com</ContactEmail>
    </DestinationAgentAddress>
    <CarrierName>Yang Ming (America) Corporation</CarrierName>
    <Carrier GUID="504c2949-a090-42fd-8161-22dc470593c4">
      <Type>Carrier</Type>
      <Name>Yang Ming (America) Corporation</Name>
      <CreatedOn>2010-09-13T07:44:28-05:00</CreatedOn>
      <Address>
        <Street>181 W.Huntington Drive, Suite 202</Street>
        <City>Monrovia</City>
        <State>CA</State>
        <ZipCode>91016</ZipCode>
        <Country Code="US">USA</Country>
        <Description>Default Billing Address</Description>
        <ContactPhone>626.782.9797</ContactPhone>
        <ContactFax>626.782.9819</ContactFax>
      </Address>
      <BillingAddress>
        <Street>181 W.Huntington Drive, Suite 202</Street>
        <City>Monrovia</City>
        <State>CA</State>
        <ZipCode>91016</ZipCode>
        <Country Code="US">USA</Country>
        <Description>Default Billing Address</Description>
        <ContactPhone>626.782.9797</ContactPhone>
        <ContactFax>626.782.9819</ContactFax>
      </BillingAddress>
      <Phone>626.782.9797 </Phone>
      <Fax>626.782.9819</Fax>
      <Balance Currency="USD">12292.499272404239</Balance>
      <TransactionDueDays>30</TransactionDueDays>
      <PaymentTerms>
        <Description>Net 30</Description>
        <NetDueDays>30</NetDueDays>
        <DiscountPercentage>0.00</DiscountPercentage>
        <DiscountPaidDays>0</DiscountPaidDays>
      </PaymentTerms>
      <OtherAddresses>
        <Address>
          <Street>SSA Terminal Berth 58 - Z985</Street>
          <Street>199 Middle Harbor Rd</Street>
          <Description>SSA Terminal OAK - Z985</Description>
        </Address>
        <Address>
          <Street>WANDO WELCH TERMINAL N598</Street>
          <Street>MT. PLEASANT, SC</Street>
          <Description>WANDO WELCH TERMINAL N598</Description>
        </Address>
        <Address>
          <Street>TraPac Oakland Firms:Y549</Street>
          <Street>2800 7th St. Berth 30,</Street>
          <City>Oakland</City>
          <State>CA</State>
          <ZipCode>94607</ZipCode>
          <Country Code="US">USA</Country>
          <Description>TraPac Oakland Firms:Y549</Description>
        </Address>
        <Address>
          <Street>GCT DELTAPORT(3891)</Street>
          <Street>Delta, BC V4M 4G5</Street>
          <Description>GCT DELTAPORT(3891)</Description>
        </Address>
        <Address>
          <Street>CN - MEMPHIS FIRMS:P484</Street>
          <Street>3588 Paul R. Lowry Road</Street>
          <Description>CN - MEMPHIS FIRMS:P484</Description>
        </Address>
        <Address>
          <Street>UNION PACIFIC RAILROAD K078</Street>
          <Description>UNION PACIFIC RAILROAD K078</Description>
        </Address>
        <Address>
          <Street>BNSF R/R - LOGISTICS PARK FIRMS:J177</Street>
          <Description>FIRMS:J177 KANSAS,KS</Description>
        </Address>
        <Address>
          <Street>(495)CN-BRAMPTON(3037)</Street>
          <Street>30 INTERMODAL DRIVE</Street>
          <Description>(495)CN-BRAMPTON(3037)</Description>
        </Address>
        <Address>
          <Street>NS Rail Landers (CHICAGO) - FIRMS I104</Street>
          <Description>NS Rail Landers (CHICAGO) - FIRMS I104</Description>
        </Address>
        <Address>
          <Street>CN - Indianapolis - FIRMS: H913</Street>
          <Description>CN - Indianapolis - FIRMS: H913</Description>
        </Address>
        <Address>
          <Street>FIRMS:H572 LOGISTICS PARK,IL</Street>
          <Description>BNSF R/R (CHICAGO) - FIRMS H572</Description>
        </Address>
        <Address>
          <Street>(495)CN-BRAMPTON(3037)</Street>
          <Street>30 INTERMODAL DRIVE</Street>
          <Street>BRAMPTON, ON L6T 5K1</Street>
          <Description>(495)CN-BRAMPTON(3037)</Description>
        </Address>
        <Address>
          <Street>CN R/R - CHICAGO/HAREY (FIRMS I092)</Street>
          <Street>15840 WEST AVE. HARVEY, IL</Street>
          <Description>CN R/R - CHICAGO/HAREY (FIRMS I092)</Description>
        </Address>
        <Address>
          <Street>FIRMS:H572 - LOGISTICS PARK,IL</Street>
          <Description>FIRMS:H572 - LOGISTICS PARK,IL</Description>
        </Address>
        <Address>
          <Street>GCT Bayonne FIRM: E364</Street>
          <Street>302 PORT JERSEY BLVD</Street>
          <Street>JERSEY CITY, NJ 07305</Street>
          <Description>GCT Bayonne FIRM: E364</Description>
        </Address>
        <Address>
          <Street>Trapac LAX Terminal - FIRMS Y258</Street>
          <Description>Trapac LAX Terminal - FIRMS Y258</Description>
        </Address>
        <Address>
          <Street>Yusen Terminals FIRMS:Y790</Street>
          <Street>701 New Dock St.</Street>
          <Street>Terminal Island, CA 90731</Street>
          <Description>Yusen Terminals FIRMS:Y790</Description>
        </Address>
        <Address>
          <Street>CSX @ INDIANAPOLIS, IN - FIRMS I950</Street>
          <Description>CSX @ INDIANAPOLIS, IN - FIRMS I950</Description>
        </Address>
        <Address>
          <Street>NS RAIL (ST LOUIS) - FIRMS J288</Street>
          <Description>NS RAIL (ST LOUIS) - FIRMS J288</Description>
        </Address>
        <Address>
          <Street>NS-RICHENBACKER(COLUMBUS)</Street>
          <Street>FIRMS - H367</Street>
          <Description>NS-RICHENBACKER(COLUMBUS)</Description>
        </Address>
        <Address>
          <Street>MASSPORT CONLEY TERMINAL - FIRMS A295</Street>
          <Street>EAST FIRST &amp; FARRAGUT ROAD,</Street>
          <Street>S. BOSTON, MA 02127</Street>
          <Description>MASSPORT CONLEY TERMINAL - FIRMS A295</Description>
        </Address>
        <Address>
          <Street>FIRMS:K961 SALT LAKE CITY,UT</Street>
          <Description>UNION PACIFIC R/R - Salt Lake UT</Description>
        </Address>
        <Address>
          <Street>PIER T136, LONG BEACH, CA</Street>
          <Street>301 HANJIN RD</Street>
          <Description>TTI LGB TRML - FIRMS:Z952</Description>
        </Address>
        <Address>
          <Street>FIRMS:J300 ST. LOUIS,MO</Street>
          <Description>FIRMS:J300 ST. LOUIS,MO</Description>
        </Address>
        <Address>
          <Street>Norfolk APM - FIRMS: N195</Street>
          <Description>Norfolk APM - FIRMS: N195</Description>
        </Address>
        <Address>
          <Street>NCSPA Wilmington - FIRMS L194</Street>
          <Street>#1 SHIPYARD BLVD.</Street>
          <City>Wilmington</City>
          <State>NC</State>
          <ZipCode>28401</ZipCode>
          <Country Code="US">USA</Country>
          <Description>NCSPA Wilmington - FIRMS L194</Description>
        </Address>
        <Address>
          <Street>VANTERM TERMINAL(3395)</Street>
          <Street>1300 STEWART STREET</Street>
          <Street>VANCOUVER, BC V5L 4X5</Street>
          <Description>Vancouver</Description>
        </Address>
        <Address>
          <Street>Firms Code : L738</Street>
          <Description>Garden City Terminal - Firms Code : L738</Description>
        </Address>
        <Address>
          <Street>ITS - FIRMS CODE: Y309</Street>
          <Description>ITS - Berth 234 LGB</Description>
        </Address>
        <Address>
          <Street>APM Terminal - FIRMS W185</Street>
          <Street>2500 Navy Way, Pier 400</Street>
          <Street>Terminal Island, CA 90731</Street>
          <Description>APM Terminals - FIRMS W185</Description>
        </Address>
        <Address>
          <Street>Firms:Z693</Street>
          <Description>Firms:Z693</Description>
        </Address>
        <Address>
          <Street>MARION UP R/R FIRMS: P279</Street>
          <Description>MARION UP R/R FIRMS: P279</Description>
        </Address>
        <Address>
          <Street>FIRMS P279</Street>
        </Address>
        <Address>
          <Street>12330 Lakeland Rd. Santa Fe Springs, CA 90670</Street>
          <City>Santa Fe Springs</City>
          <State>CA</State>
          <ZipCode>90670</ZipCode>
          <Country Code="US">USA</Country>
          <Description>Phoenix Warehouse of CA, LLC.</Description>
        </Address>
        <Address>
          <Street>NORTH CONTAINER TERMINAL - FIRMS: L391</Street>
          <Street>100 Remount Rd. N.</Street>
          <Street>Charleston, SC 29406</Street>
          <Description>NORTH CONTAINER TERMINAL - Charleston</Description>
        </Address>
        <Address>
          <Street>Berth 246 Long Beach CA   FIRMS W182</Street>
          <Street>1521 Harbor Scenic Dr.</Street>
          <Description>LGB TRML FIRMS W182</Description>
          <ContactPhone>562-590-8728</ContactPhone>
        </Address>
        <Address>
          <Street>13131 Daairy Ashford Rd. Suite 300</Street>
          <City>Sugarland</City>
          <State>CA</State>
          <ZipCode>77478</ZipCode>
          <Country Code="US">USA</Country>
          <Description>Yang Ming (America) Corporation</Description>
          <ContactPhone>281.201.5150</ContactPhone>
          <ContactEmail>perdiem@us.yangming.com</ContactEmail>
        </Address>
        <Address>
          <Street>MAHER TERMINAL - E416 - BERTH 64</Street>
          <Street>PORT ELIZABETH, NJ</Street>
          <Description>MAHER TERMINAL - E416 - BERTH 64</Description>
        </Address>
        <Address>
          <Street>Berth 126. San Pedro - FIRMS Y773</Street>
          <City>San Pedro</City>
          <State>CA</State>
          <Country Code="US">USA</Country>
          <Description>WBCT LAX TRML FIRMS Y773</Description>
          <ContactPhone>310.519.2349</ContactPhone>
        </Address>
        <Address>
          <Street>13131 DAIRY ASHFORD RD, SUITE 300</Street>
          <City>Sugarland</City>
          <State>TX</State>
          <ZipCode>77478</ZipCode>
          <Country Code="US">USA</Country>
          <Description>Yang Ming (America) Corporation</Description>
          <ContactPhone>281.201.5150</ContactPhone>
          <ContactEmail>perdiem@us.yangming.com</ContactEmail>
        </Address>
      </OtherAddresses>
      <IsPrepaid>false</IsPrepaid>
      <CarrierInfo>
        <CarrierTypeCode>Ocean</CarrierTypeCode>
        <SCACNumber>YMLU</SCACNumber>
      </CarrierInfo>
    </Carrier>
    <CarrierAddress>
      <Street>181 W.Huntington Drive, Suite 202</Street>
      <City>Monrovia</City>
      <State>CA</State>
      <ZipCode>91016</ZipCode>
      <Country Code="US">USA</Country>
      <Description>Default Billing Address</Description>
      <ContactPhone>626.782.9797</ContactPhone>
      <ContactFax>626.782.9819</ContactFax>
    </CarrierAddress>
    <Items>
      <Item GUID="e500f82c-91e0-4a75-bab1-64ffe10cca3b" Type="WI">
        <Version>105</Version>
        <Status>Loaded</Status>
        <Pieces>1</Pieces>
        <PieceQuantity>0.00</PieceQuantity>
        <IsSummarized>false</IsSummarized>
        <PackageName>40 High Cube</PackageName>
        <WHRItemID>0</WHRItemID>
        <Length Unit="m">12.06000000000000049738</Length>
        <Height Unit="m">2.59100000000000019185</Height>
        <Width Unit="m">2.43800000000000016698</Width>
        <Weight Unit="kg">0.00</Weight>
        <ContainedPiecesWeightIncluded>false</ContainedPiecesWeightIncluded>
        <Volume Unit="m3">76.181299313332</Volume>
        <VolumeWeight Unit="vlb">28005.22985510987928137183</VolumeWeight>
        <PieceWeight Unit="kg">0.00</PieceWeight>
        <PieceVolume Unit="m3">0.00</PieceVolume>
        <Package>
          <Type>Container</Type>
          <Code>CNT</Code>
          <Name>40 High Cube</Name>
          <Length Unit="m">12.06000000000000049738</Length>
          <Height Unit="m">2.59100000000000019185</Height>
          <Width Unit="m">2.43800000000000016698</Width>
          <Volume Unit="m3">76.40000000000000568434</Volume>
          <MaxWeight Unit="kg">26330.00</MaxWeight>
          <ContainerCode>40</ContainerCode>
          <ContainerEquipType>45G0</ContainerEquipType>
          <Methods>
            <Method>Ocean</Method>
            <Method>Ground</Method>
          </Methods>
        </Package>
        <InShipmentGUID>aad8057c-3d3c-4cf3-b0c5-e5e631276dc0</InShipmentGUID>
        <IncludeInSED>false</IncludeInSED>
        <IsContainer>true</IsContainer>
        <InMasterWayBillNumber>MBL4978OI</InMasterWayBillNumber>
        <InHouseWayBillNumber>SH19120796</InHouseWayBillNumber>
        <ArrivalDate>2020-01-28T16:27:02-05:00</ArrivalDate>
        <ContainerInfo>
          <GeneratorSetup>false</GeneratorSetup>
          <IsNonOperatingReefer>false</IsNonOperatingReefer>
        </ContainerInfo>
        <OrderIndex>1</OrderIndex>
        <IsPallet>false</IsPallet>
        <IsOverstock>false</IsOverstock>
        <NotLoaded>false</NotLoaded>
        <InTask>false</InTask>
      </Item>
    </Items>
    <MeasurementUnits>
      <LengthUnit>m</LengthUnit>
      <VolumeUnit>m3</VolumeUnit>
      <WeightUnit>kg</WeightUnit>
      <VolumeWeightUnit>vlb</VolumeWeightUnit>
      <AreaUnit>m2</AreaUnit>
      <LengthPrecision>3</LengthPrecision>
      <VolumePrecision>4</VolumePrecision>
      <WeightPrecision>3</WeightPrecision>
      <VolumeWeightPrecision>3</VolumeWeightPrecision>
      <AreaPrecision>3</AreaPrecision>
      <VolumeWeightFactor>166.00</VolumeWeightFactor>
    </MeasurementUnits>
    <CreatorNetworkID>21849</CreatorNetworkID>
    <Events>
      <Event>
        <Date>2019-12-26T16:29:59-05:00</Date>
        <EventDefinition>
          <Name>1- Booking Pending</Name>
          <IncludeInTracking>true</IncludeInTracking>
        </EventDefinition>
        <IncludeInTracking>true</IncludeInTracking>
        <OwnerType>SH</OwnerType>
        <OwnerNumber>MBL4978OI</OwnerNumber>
        <OwnerGUID>db1fd1e5-a096-4673-a76c-3e629da72bc9</OwnerGUID>
      </Event>
      <Event>
        <Date>2019-12-26T16:29:59-05:00</Date>
        <EventDefinition>
          <Name>1- Booking Pending</Name>
          <IncludeInTracking>true</IncludeInTracking>
        </EventDefinition>
        <IncludeInTracking>true</IncludeInTracking>
        <OwnerType>SH</OwnerType>
        <OwnerNumber>SH19120796</OwnerNumber>
        <OwnerGUID>aad8057c-3d3c-4cf3-b0c5-e5e631276dc0</OwnerGUID>
      </Event>
      <Event>
        <Date>2019-12-26T16:30:20-05:00</Date>
        <EventDefinition>
          <Name>2- Booking Confirmed</Name>
          <IncludeInTracking>true</IncludeInTracking>
        </EventDefinition>
        <IncludeInTracking>true</IncludeInTracking>
        <OwnerType>SH</OwnerType>
        <OwnerNumber>SH19120796</OwnerNumber>
        <OwnerGUID>aad8057c-3d3c-4cf3-b0c5-e5e631276dc0</OwnerGUID>
      </Event>
    </Events>
    <TotalPieces>1</TotalPieces>
    <TotalWeight Unit="kg">0.00</TotalWeight>
    <TotalVolume Unit="m3">76.181299313332</TotalVolume>
    <TotalVolumeWeight Unit="vlb">28005.22985510987928137183</TotalVolumeWeight>
    <ChargeableWeight Unit="kg">12702.95859302662938716821</ChargeableWeight>
    <TotalValue Currency="USD">0.00</TotalValue>
    <OriginPort Code="SHA">
      <Country Code="CN">CN</Country>
      <Method>Air</Method>
      <Method>Ocean</Method>
      <Method>Ground</Method>
      <Method>Mail</Method>
      <Name>Shanghai, China</Name>
      <Subdivision></Subdivision>
      <Remarks>subdivision-31</Remarks>
    </OriginPort>
    <DestinationPort Code="LAX">
      <Country Code="US">USA</Country>
      <Method>Air</Method>
      <Method>Ocean</Method>
      <Method>Ground</Method>
      <Method>Mail</Method>
      <Name>Los Angeles, CA</Name>
      <Subdivision>CA</Subdivision>
    </DestinationPort>
    <DeliveryPort Code="CHI">
      <Country Code="US">USA</Country>
      <Method>Air</Method>
      <Method>Ocean</Method>
      <Method>Ground</Method>
      <Name>Chicago</Name>
      <Subdivision>IL</Subdivision>
    </DeliveryPort>
    <Status>Loaded</Status>
    <LayoutType>House</LayoutType>
    <Direction>Incoming</Direction>
    <EstimatedArrivalDate>2020-01-28T16:27:02-05:00</EstimatedArrivalDate>
    <ActualArrivalDate>2019-12-26T16:29:59-05:00</ActualArrivalDate>
    <EstimatedDepartureDate>2020-01-14T16:27:02-05:00</EstimatedDepartureDate>
    <ActualDepartureDate>2019-12-26T16:29:59-05:00</ActualDepartureDate>
    <BillingClient GUID="186510fc-e1c4-4b8b-a0c4-99363b15bd41">
      <Type>Client</Type>
      <Name>Cnee</Name>
      <CreatedOn>2018-05-08T13:14:48-05:00</CreatedOn>
      <Address>
        <Street>TEST STREET NUMBER</Street>
        <City>Red Bank</City>
        <State>NJ</State>
        <ZipCode>07701</ZipCode>
        <Country Code="US">USA</Country>
        <Description>Default Shipping Address</Description>
      </Address>
      <BillingAddress>
        <Street>TEST STREET NUMBER</Street>
        <City>Red Bank</City>
        <State>NJ</State>
        <ZipCode>07701</ZipCode>
        <Country Code="US">USA</Country>
        <Description>Default Billing Address</Description>
      </BillingAddress>
      <AccountNumber>CX10136</AccountNumber>
      <Balance Currency="USD">114517.15998894054443</Balance>
      <TransactionDueDays>15</TransactionDueDays>
      <PaymentTerms>
        <Description>Net 15</Description>
        <NetDueDays>15</NetDueDays>
        <DiscountPercentage>0.00</DiscountPercentage>
        <DiscountPaidDays>0</DiscountPaidDays>
      </PaymentTerms>
      <IsPrepaid>false</IsPrepaid>
    </BillingClient>
    <ExecutedPlace>EL Segundo</ExecutedPlace>
    <MasterGUID>99999999-a096-4673-a76c-3e629da72bc9</MasterGUID>
    <LastDateOfDeparture>2019-12-26T16:27:02-05:00</LastDateOfDeparture>
    <SpottingDate>2019-12-26T16:27:02-05:00</SpottingDate>
    <PickupDate>2019-12-26T16:27:02-05:00</PickupDate>
    <CutoffDate>2019-12-26T16:27:02-05:00</CutoffDate>
    <MasterWayBillNumber>MBL4978OI</MasterWayBillNumber>
    <MasterNumber>MBL4978OI</MasterNumber>
    <HasAttachments>true</HasAttachments>
    <ShipmentOptions>
      <IsShipperConsigneeRelated>false</IsShipperConsigneeRelated>
      <IsRoutedTransaction>true</IsRoutedTransaction>
      <IsAirWayBillDetailExpanded>false</IsAirWayBillDetailExpanded>
      <IsBillOfLadingDetailExpanded>false</IsBillOfLadingDetailExpanded>
      <IsCargoManifestDetailExpanded>true</IsCargoManifestDetailExpanded>
      <FillDocsWithAccountingInfo>true</FillDocsWithAccountingInfo>
      <AirWayBillWeightUnit>Both</AirWayBillWeightUnit>
      <BillOfLadingWeightUnit>Both</BillOfLadingWeightUnit>
      <ShowContainerDetails>false</ShowContainerDetails>
      <ShowWHRsInCargoManifest>false</ShowWHRsInCargoManifest>
      <ShowDimensionsInAWB>true</ShowDimensionsInAWB>
      <ShowDimensionsDetailedInAWB>false</ShowDimensionsDetailedInAWB>
      <UseNotesAsMarksNumbersInBL>false</UseNotesAsMarksNumbersInBL>
      <BillOfLadingGroupSimilarItems>false</BillOfLadingGroupSimilarItems>
    </ShipmentOptions>
    <IsLessThanFullLoad>true</IsLessThanFullLoad>
    <Service>PortToPort</Service>
    <IsOnline>false</IsOnline>
    <IsLiquidated>false</IsLiquidated>
    <CreatedFrom>
      <GUID>c4a7f6eb-0695-4376-8994-7e18f0b2912b</GUID>
      <Type>OceanBooking</Type>
      <Number>EWL24195</Number>
    </CreatedFrom>
    <TotalContainers>1</TotalContainers>
    <Containers40Foot>1</Containers40Foot>
    <OceanShipmentInfo>
      <BillOfLadingNumber>SH19120796</BillOfLadingNumber>
      <VesselName>YM MOVEMENT</VesselName>
      <PlaceOfDeliveryByOnCarrier>Chicago</PlaceOfDeliveryByOnCarrier>
    </OceanShipmentInfo>
  </OceanShipment>
</Shipments>     

I used the xsd.exe utility from msdn to create classes. I had to download both the schema you posted and the common.xsd (same path a posted schema with different filename). Then pasted the classes generated into program. Then used following code

        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            XmlReader reader = XmlReader.Create(FILENAME);
            XmlSerializer serializer = new XmlSerializer(typeof(ShipmentList));
            ShipmentList shipmentList = (ShipmentList)serializer.Deserialize(reader);
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM