如何向 XMLrootElement 添加更多标签
how to add more tags to XMLrootElement
我想用 JAXB 生成一个 xml 文件,我需要在请求 schemaVersion="10.0" ...
这是我生成 xml 文件的代码:
包-info.java
@XmlSchema(namespace = "http://www.dhl.com/datatypes_global",location="datatypes_global_v10" )
// elementFormDefault = XmlNsForm.QUALIFIEDc'est à dire que les @XmlElement seront pas prefixé
//// xmlns:req='http://www.dhl.com' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.dhl.com ship-val-req_AP.xsd'
package dhl.request.vo_10.document;
/**Il faut que ce fichier sera nommé package dhl.-info : décrit nomspace xml request*/
import javax.xml.bind.annotation.XmlSchema;
OprDocumentVO.java
package dhl.request.vo_10.document;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import dhl.request.vo_10.billing.OprBillingVO;
import dhl.request.vo_10.commodity.OprCommodityVO;
import dhl.request.vo_10.consignee.OprConsigneeVO;
import dhl.request.vo_10.document.exportDeclaration.OprExportDeclarationVO;
import dhl.request.vo_10.document.label.OprLabelVO;
import dhl.request.vo_10.dutiable.OprDutiableVO;
import dhl.request.vo_10.reference.OprReferenceVO;
import dhl.request.vo_10.request.OprRequestVO;
import dhl.request.vo_10.shipmentDetails.OprShipmentDetailsVO;
import dhl.request.vo_10.shipper.OprShipperVO;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="OprDocumentVO",propOrder = {
"request",
"languageCode",
"billing",
"consignee",
"commodity",
"dutiable",
"reference",
"shipmentDetails",
"shipper",
"specialService",
"regionCode",
"requestedPickupTime",
"newShipper",
"useDHLInvoice",
"dHLInvoiceLanguageCode",
"dHLInvoiceType",
"exportDeclaration",
"numberOfArchiveDoc",
"requestArchiveDoc",
"labelImageFormat",
"eProcShip",
"label",
"getPriceEstimate",
"singlePieceImage"
})
@XmlRootElement(name="ShipmentRequest" )
public class OprDocumentVO
{
public OprRequestVO getRequest() {
return request;
}
public void setRequest(OprRequestVO request) {
this.request = request;
}
public String getLanguageCode() {
return languageCode;
}
public void setLanguageCode(String languageCode) {
this.languageCode = languageCode;
}
public OprBillingVO getBilling() {
return billing;
}
public void setBilling(OprBillingVO billing) {
this.billing = billing;
}
public OprConsigneeVO getConsignee() {
return consignee;
}
public void setConsignee(OprConsigneeVO consignee) {
this.consignee = consignee;
}
public OprCommodityVO getCommodity() {
return commodity;
}
public void setCommodity(OprCommodityVO commodity) {
this.commodity = commodity;
}
public OprDutiableVO getDutiable() {
return dutiable;
}
public void setDutiable(OprDutiableVO dutiable) {
this.dutiable = dutiable;
}
public OprReferenceVO getReference() {
return reference;
}
public void setReference(OprReferenceVO reference) {
this.reference = reference;
}
public OprShipmentDetailsVO getShipmentDetails() {
return shipmentDetails;
}
public void setShipmentDetails(OprShipmentDetailsVO shipmentDetails) {
this.shipmentDetails = shipmentDetails;
}
public OprShipperVO getShipper() {
return shipper;
}
public void setShipper(OprShipperVO shipper) {
this.shipper = shipper;
}
@XmlElement(name = "GetPriceEstimate", nillable = false, required = true)
private String getPriceEstimate;
@XmlElement(name = "SinglePieceImage", nillable = false, required = true)
private String singlePieceImage;
@XmlElement(name = "LAbel", nillable = false, required = true)
private OprLabelVO label;
@XmlElement(name = "NumberOfArchiveDoc", nillable = false, required = true)
private String numberOfArchiveDoc;
@XmlElement(name = "RequestArchiveDoc", nillable = false, required = true)
private String requestArchiveDoc;
@XmlElement(name = "LabelImageFormat", nillable = false, required = true)
private String labelImageFormat;
@XmlElement(name = "EProcShip", nillable = false, required = true)
private String eProcShip;
@XmlElement(name = "ExportDeclaration", nillable = false, required = true)
private OprExportDeclarationVO exportDeclaration;
@XmlElement(name = "UseDHLInvoice", nillable = false, required = true)
private String useDHLInvoice;
@XmlElement(name = "DHLInvoiceLanguageCode", nillable = false, required = true)
private String dHLInvoiceLanguageCode;
@XmlElement(name = "DHLInvoiceType", nillable = false, required = true)
private String dHLInvoiceType;
@XmlElement(name = "Request", nillable = false, required = true)
private OprRequestVO request;
@XmlElement(name = "LanguageCode", nillable = false, required = true)
private String languageCode;
@XmlElement(name = "Billing", nillable = false, required = true)
private OprBillingVO billing;
@XmlElement(name = "Consignee", nillable = false, required = true)
private OprConsigneeVO consignee;
@XmlElement(name = "Commodity", nillable = false, required = true)
private OprCommodityVO commodity ;
@XmlElement(name = "Dutiable", nillable = false, required = true)
private OprDutiableVO dutiable ;
@XmlElement(name = "Reference", nillable = false, required = true)
private OprReferenceVO reference ;
@XmlElement(name = "ShipmentDetails", nillable = false, required = true)
private OprShipmentDetailsVO shipmentDetails ;
@XmlElement(name = "Shipper", nillable = false, required = true)
private OprShipperVO shipper ;
@XmlElement(name = "SpecialService", nillable = false, required = true)
private dhl.request.vo_10.document.specialService.OprSpecialServiceVO specialService ;
@XmlElement(name = "RegionCode", nillable = false, required = true)
private String regionCode;
@XmlElement(name = "RequestedPickupTime", nillable = false, required = true)
private String requestedPickupTime;
@XmlElement(name = "NewShipper", nillable = false, required = true)
private String newShipper;
public String getRegionCode() {
return regionCode;
}
public void setRegionCode(String regionCode) {
this.regionCode = regionCode;
}
public OprExportDeclarationVO getExportDeclaration() {
return exportDeclaration;
}
public void setExportDeclaration(OprExportDeclarationVO exportDeclaration) {
this.exportDeclaration = exportDeclaration;
}
public dhl.request.vo_10.document.specialService.OprSpecialServiceVO getSpecialService() {
return specialService;
}
public void setSpecialService(dhl.request.vo_10.document.specialService.OprSpecialServiceVO specialService) {
this.specialService = specialService;
}
public String getNumberOfArchiveDoc() {
return numberOfArchiveDoc;
}
public void setNumberOfArchiveDoc(String numberOfArchiveDoc) {
this.numberOfArchiveDoc = numberOfArchiveDoc;
}
public String getRequestArchiveDoc() {
return requestArchiveDoc;
}
public void setRequestArchiveDoc(String requestArchiveDoc) {
this.requestArchiveDoc = requestArchiveDoc;
}
public String getLabelImageFormat() {
return labelImageFormat;
}
public void setLabelImageFormat(String labelImageFormat) {
this.labelImageFormat = labelImageFormat;
}
public String geteProcShip() {
return eProcShip;
}
public void seteProcShip(String eProcShip) {
this.eProcShip = eProcShip;
}
public String getGetPriceEstimate() {
return getPriceEstimate;
}
public void setGetPriceEstimate(String getPriceEstimate) {
this.getPriceEstimate = getPriceEstimate;
}
public String getSinglePieceImage() {
return singlePieceImage;
}
public void setSinglePieceImage(String singlePieceImage) {
this.singlePieceImage = singlePieceImage;
}
public OprLabelVO getLabel() {
return label;
}
public void setLabel(OprLabelVO label) {
this.label = label;
}
public String getRequestedPickupTime() {
return requestedPickupTime;
}
public void setRequestedPickupTime(String requestedPickupTime) {
this.requestedPickupTime = requestedPickupTime;
}
public String getNewShipper() {
return newShipper;
}
public void setNewShipper(String newShipper) {
this.newShipper = newShipper;
}
public String getUseDHLInvoice() {
return useDHLInvoice;
}
public void setUseDHLInvoice(String useDHLInvoice) {
this.useDHLInvoice = useDHLInvoice;
}
public String getdHLInvoiceLanguageCode() {
return dHLInvoiceLanguageCode;
}
public void setdHLInvoiceLanguageCode(String dHLInvoiceLanguageCode) {
this.dHLInvoiceLanguageCode = dHLInvoiceLanguageCode;
}
public String getdHLInvoiceType() {
return dHLInvoiceType;
}
public void setdHLInvoiceType(String dHLInvoiceType) {
this.dHLInvoiceType = dHLInvoiceType;
}
}
获取此 xml 文件:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<req:ShipmentRequest xmlns:req="http://www.dhl.com/datatypes_global">
<Request>
<ServiceHeader>
<MessageTime>2021-05-17T11:29:06+00:00</MessageTime>
<MessageReference>1234567890123456789012345678901</MessageReference>
<SiteID>CIMAXMLPI</SiteID>
<Password>3p7jW0tamq</Password>
</ServiceHeader>
<MetaData>
<SoftwareName>software name</SoftwareName>
<SoftwareVersion>1.10</SoftwareVersion>
</MetaData>
</Request>
<LanguageCode>EN</LanguageCode>
<Billing>
<ShipperAccountNumber>359045226</ShipperAccountNumber>
<ShippingPaymentType>S</ShippingPaymentType>
<DutyPaymentType>R</DutyPaymentType>
</Billing>
<Consignee>
<CompanyName>MOHAMED AIT OULID</CompanyName>
<AddressLine>2717 ARLINGTON DRIVE APART N 102 AL</AddressLine>
<AddressLine>ESCANDIRA VIRGINIA </AddressLine>
<City>ALEXANDRI</City>
<PostalCode>22306</PostalCode>
<CountryCode>US</CountryCode>
<CountryName>United States</CountryName>
<Contact>
<PersonName>MOHAMED AIT OULID </PersonName>
<PhoneNumber>17034779922</PhoneNumber>
</Contact>
<BusinessPartyTypeCode>BUSINESSPARTYTYPECODE</BusinessPartyTypeCode>
<RegistrationNumbers>
<RegistrationNumbers>
<Number>NUMBER</Number>
<NumberTypeCode>NUMBERTYPECODE</NumberTypeCode>
<NumberIssuerCountryCode>NUMBERISSUERCOUNTRYCODE</NumberIssuerCountryCode>
</RegistrationNumbers>
</RegistrationNumbers>
</Consignee>
<Dutiable>
<DeclaredValue>18.00</DeclaredValue>
<DeclaredCurrency>MAD</DeclaredCurrency>
<ShipperEIN>MA-BEN</ShipperEIN>
<TermsOfTrade>DDU</TermsOfTrade>
<Filing>
<filingType>FILINGTYPE</filingType>
<ITN>ITN</ITN>
</Filing>
</Dutiable>
<Reference>
<ReferenceID>46009000875384D</ReferenceID>
<ReferenceType>ID</ReferenceType>
</Reference>
<ShipmentDetails>
<CurrencyCode>MAD</CurrencyCode>
<Pieces>
<Piece>
<Weight>2.33</Weight>
<Depth>0</Depth>
<Width>0</Width>
<Height>0</Height>
<PieceID>1</PieceID>
<PackageType>EE</PackageType>
</Piece>
</Pieces>
<PackageType>EE</PackageType>
<Weight>2.376</Weight>
<DimensionUnit>C</DimensionUnit>
<WeightUnit>K</WeightUnit>
<GlobalProductCode>P</GlobalProductCode>
<LocalProductCode>P</LocalProductCode>
<Date>2021-05-17</Date>
<Contents>VETEMENTS ET BABOUCHES</Contents>
<IsDutiable>Y</IsDutiable>
</ShipmentDetails>
<Shipper>
<ShipperID>359045226</ShipperID>
<CompanyName>LOTFI HAYAT</CompanyName>
<AddressLine>HAY HANAA SOK HANA N 7 </AddressLine>
<City>CASABLANCA </City>
<PostalCode>20000</PostalCode>
<CountryCode>MA</CountryCode>
<CountryName>MOROCCO</CountryName>
<Contact>
<PersonName>LOTIF HAYAT </PersonName>
<PhoneNumber>0614183031</PhoneNumber>
</Contact>
</Shipper>
<SpecialService>
<SpecialServiceType>DS</SpecialServiceType>
</SpecialService>
<RegionCode>REGION CODE</RegionCode>
<RequestedPickupTime>N</RequestedPickupTime>
<NewShipper>N</NewShipper>
<UseDHLInvoice>Y</UseDHLInvoice>
<DHLInvoiceLanguageCode>en</DHLInvoiceLanguageCode>
<DHLInvoiceType>CMI</DHLInvoiceType>
<ExportDeclaration>
<ExportReason>sales</ExportReason>
<ExportReasonCode>P</ExportReasonCode>
<InvoiceNumber>MyDHLAPI - INV-001</InvoiceNumber>
<InvoiceDate>2021-04-29</InvoiceDate>
<TermsOfPayment>60 days</TermsOfPayment>
<PayerGSTVAT>yes</PayerGSTVAT>
<ReceiverReference>ReceiverReference</ReceiverReference>
<ExporterId>43244325</ExporterId>
<ExporterCode>ExporterCode</ExporterCode>
<InvoiceInstructions>This is invoice instruction</InvoiceInstructions>
<PlaceOfIncoterm>GAILDORF PORT</PlaceOfIncoterm>
<ShipmentPurpose>COMMERCIAL</ShipmentPurpose>
<DocumentFunction>IMPORT</DocumentFunction>
<InvoiceTotalNetWeight>0.400</InvoiceTotalNetWeight>
<InvoiceTotalGrossWeight>0.500</InvoiceTotalGrossWeight>
<CustomsDocuments>
<CustomsDocument>
<CustomsDocumentType>INV</CustomsDocumentType>
<CustomsDocumentID>MyDHLAPI - CUSDOC-001</CustomsDocumentID>
</CustomsDocument>
</CustomsDocuments>
<ExportLineItem>
<LineNumber>1</LineNumber>
<Quantity>1</Quantity>
<QuantityUnit>PCS</QuantityUnit>
<Description>Fall collection: knitted vegetarian top white US 5</Description>
<Value>56.525</Value>
<CommodityCode>6109.10.0010</CommodityCode>
<Weight>
<Weight>0.200</Weight>
<WeightUnit>K</WeightUnit>
</Weight>
<ManufactureCountryCode>MA</ManufactureCountryCode>
<ImportCommodityCode>6109.10.0010</ImportCommodityCode>
<ItemReferences>
<ItemReference>
<ItemReferenceType>PAN</ItemReferenceType>
<ItemReferenceNumber>10597122</ItemReferenceNumber>
</ItemReference>
</ItemReferences>
</ExportLineItem>
<InvoiceReferences>
<InvoiceReference>
<InvoiceReferenceType>OID</InvoiceReferenceType>
<InvoiceReferenceNumber>OID-7839749374</InvoiceReferenceNumber>
</InvoiceReference>
</InvoiceReferences>
</ExportDeclaration>
<NumberOfArchiveDoc>1</NumberOfArchiveDoc>
<RequestArchiveDoc>Y</RequestArchiveDoc>
<LabelImageFormat>PDF</LabelImageFormat>
<LAbel>
<HideAccount>N</HideAccount>
<LabelTemplate>8X4_thermal</LabelTemplate>
<Logo>Y</Logo>
</LAbel>
<GetPriceEstimate>N</GetPriceEstimate>
<SinglePieceImage>N</SinglePieceImage>
</req:ShipmentRequest>
我使用 jaxB API 中的 marchal 和 unmarchal 函数将我所有的 java 对象转换为 xml 请求
感谢您的帮助
解决方法很简单。
您需要添加一个 schemaVersion
属性 到您的根 class
并用 @XmlAttribute
注释,而不是 @XmlElement
.
@XmlAttribute(name = "schemaVersion")
private String schemaVersion;
// + getter and setter
我想用 JAXB 生成一个 xml 文件,我需要在请求
这是我生成 xml 文件的代码:
包-info.java
@XmlSchema(namespace = "http://www.dhl.com/datatypes_global",location="datatypes_global_v10" )
// elementFormDefault = XmlNsForm.QUALIFIEDc'est à dire que les @XmlElement seront pas prefixé
//// xmlns:req='http://www.dhl.com' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.dhl.com ship-val-req_AP.xsd'
package dhl.request.vo_10.document;
/**Il faut que ce fichier sera nommé package dhl.-info : décrit nomspace xml request*/
import javax.xml.bind.annotation.XmlSchema;
OprDocumentVO.java
package dhl.request.vo_10.document;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import dhl.request.vo_10.billing.OprBillingVO;
import dhl.request.vo_10.commodity.OprCommodityVO;
import dhl.request.vo_10.consignee.OprConsigneeVO;
import dhl.request.vo_10.document.exportDeclaration.OprExportDeclarationVO;
import dhl.request.vo_10.document.label.OprLabelVO;
import dhl.request.vo_10.dutiable.OprDutiableVO;
import dhl.request.vo_10.reference.OprReferenceVO;
import dhl.request.vo_10.request.OprRequestVO;
import dhl.request.vo_10.shipmentDetails.OprShipmentDetailsVO;
import dhl.request.vo_10.shipper.OprShipperVO;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="OprDocumentVO",propOrder = {
"request",
"languageCode",
"billing",
"consignee",
"commodity",
"dutiable",
"reference",
"shipmentDetails",
"shipper",
"specialService",
"regionCode",
"requestedPickupTime",
"newShipper",
"useDHLInvoice",
"dHLInvoiceLanguageCode",
"dHLInvoiceType",
"exportDeclaration",
"numberOfArchiveDoc",
"requestArchiveDoc",
"labelImageFormat",
"eProcShip",
"label",
"getPriceEstimate",
"singlePieceImage"
})
@XmlRootElement(name="ShipmentRequest" )
public class OprDocumentVO
{
public OprRequestVO getRequest() {
return request;
}
public void setRequest(OprRequestVO request) {
this.request = request;
}
public String getLanguageCode() {
return languageCode;
}
public void setLanguageCode(String languageCode) {
this.languageCode = languageCode;
}
public OprBillingVO getBilling() {
return billing;
}
public void setBilling(OprBillingVO billing) {
this.billing = billing;
}
public OprConsigneeVO getConsignee() {
return consignee;
}
public void setConsignee(OprConsigneeVO consignee) {
this.consignee = consignee;
}
public OprCommodityVO getCommodity() {
return commodity;
}
public void setCommodity(OprCommodityVO commodity) {
this.commodity = commodity;
}
public OprDutiableVO getDutiable() {
return dutiable;
}
public void setDutiable(OprDutiableVO dutiable) {
this.dutiable = dutiable;
}
public OprReferenceVO getReference() {
return reference;
}
public void setReference(OprReferenceVO reference) {
this.reference = reference;
}
public OprShipmentDetailsVO getShipmentDetails() {
return shipmentDetails;
}
public void setShipmentDetails(OprShipmentDetailsVO shipmentDetails) {
this.shipmentDetails = shipmentDetails;
}
public OprShipperVO getShipper() {
return shipper;
}
public void setShipper(OprShipperVO shipper) {
this.shipper = shipper;
}
@XmlElement(name = "GetPriceEstimate", nillable = false, required = true)
private String getPriceEstimate;
@XmlElement(name = "SinglePieceImage", nillable = false, required = true)
private String singlePieceImage;
@XmlElement(name = "LAbel", nillable = false, required = true)
private OprLabelVO label;
@XmlElement(name = "NumberOfArchiveDoc", nillable = false, required = true)
private String numberOfArchiveDoc;
@XmlElement(name = "RequestArchiveDoc", nillable = false, required = true)
private String requestArchiveDoc;
@XmlElement(name = "LabelImageFormat", nillable = false, required = true)
private String labelImageFormat;
@XmlElement(name = "EProcShip", nillable = false, required = true)
private String eProcShip;
@XmlElement(name = "ExportDeclaration", nillable = false, required = true)
private OprExportDeclarationVO exportDeclaration;
@XmlElement(name = "UseDHLInvoice", nillable = false, required = true)
private String useDHLInvoice;
@XmlElement(name = "DHLInvoiceLanguageCode", nillable = false, required = true)
private String dHLInvoiceLanguageCode;
@XmlElement(name = "DHLInvoiceType", nillable = false, required = true)
private String dHLInvoiceType;
@XmlElement(name = "Request", nillable = false, required = true)
private OprRequestVO request;
@XmlElement(name = "LanguageCode", nillable = false, required = true)
private String languageCode;
@XmlElement(name = "Billing", nillable = false, required = true)
private OprBillingVO billing;
@XmlElement(name = "Consignee", nillable = false, required = true)
private OprConsigneeVO consignee;
@XmlElement(name = "Commodity", nillable = false, required = true)
private OprCommodityVO commodity ;
@XmlElement(name = "Dutiable", nillable = false, required = true)
private OprDutiableVO dutiable ;
@XmlElement(name = "Reference", nillable = false, required = true)
private OprReferenceVO reference ;
@XmlElement(name = "ShipmentDetails", nillable = false, required = true)
private OprShipmentDetailsVO shipmentDetails ;
@XmlElement(name = "Shipper", nillable = false, required = true)
private OprShipperVO shipper ;
@XmlElement(name = "SpecialService", nillable = false, required = true)
private dhl.request.vo_10.document.specialService.OprSpecialServiceVO specialService ;
@XmlElement(name = "RegionCode", nillable = false, required = true)
private String regionCode;
@XmlElement(name = "RequestedPickupTime", nillable = false, required = true)
private String requestedPickupTime;
@XmlElement(name = "NewShipper", nillable = false, required = true)
private String newShipper;
public String getRegionCode() {
return regionCode;
}
public void setRegionCode(String regionCode) {
this.regionCode = regionCode;
}
public OprExportDeclarationVO getExportDeclaration() {
return exportDeclaration;
}
public void setExportDeclaration(OprExportDeclarationVO exportDeclaration) {
this.exportDeclaration = exportDeclaration;
}
public dhl.request.vo_10.document.specialService.OprSpecialServiceVO getSpecialService() {
return specialService;
}
public void setSpecialService(dhl.request.vo_10.document.specialService.OprSpecialServiceVO specialService) {
this.specialService = specialService;
}
public String getNumberOfArchiveDoc() {
return numberOfArchiveDoc;
}
public void setNumberOfArchiveDoc(String numberOfArchiveDoc) {
this.numberOfArchiveDoc = numberOfArchiveDoc;
}
public String getRequestArchiveDoc() {
return requestArchiveDoc;
}
public void setRequestArchiveDoc(String requestArchiveDoc) {
this.requestArchiveDoc = requestArchiveDoc;
}
public String getLabelImageFormat() {
return labelImageFormat;
}
public void setLabelImageFormat(String labelImageFormat) {
this.labelImageFormat = labelImageFormat;
}
public String geteProcShip() {
return eProcShip;
}
public void seteProcShip(String eProcShip) {
this.eProcShip = eProcShip;
}
public String getGetPriceEstimate() {
return getPriceEstimate;
}
public void setGetPriceEstimate(String getPriceEstimate) {
this.getPriceEstimate = getPriceEstimate;
}
public String getSinglePieceImage() {
return singlePieceImage;
}
public void setSinglePieceImage(String singlePieceImage) {
this.singlePieceImage = singlePieceImage;
}
public OprLabelVO getLabel() {
return label;
}
public void setLabel(OprLabelVO label) {
this.label = label;
}
public String getRequestedPickupTime() {
return requestedPickupTime;
}
public void setRequestedPickupTime(String requestedPickupTime) {
this.requestedPickupTime = requestedPickupTime;
}
public String getNewShipper() {
return newShipper;
}
public void setNewShipper(String newShipper) {
this.newShipper = newShipper;
}
public String getUseDHLInvoice() {
return useDHLInvoice;
}
public void setUseDHLInvoice(String useDHLInvoice) {
this.useDHLInvoice = useDHLInvoice;
}
public String getdHLInvoiceLanguageCode() {
return dHLInvoiceLanguageCode;
}
public void setdHLInvoiceLanguageCode(String dHLInvoiceLanguageCode) {
this.dHLInvoiceLanguageCode = dHLInvoiceLanguageCode;
}
public String getdHLInvoiceType() {
return dHLInvoiceType;
}
public void setdHLInvoiceType(String dHLInvoiceType) {
this.dHLInvoiceType = dHLInvoiceType;
}
}
获取此 xml 文件:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<req:ShipmentRequest xmlns:req="http://www.dhl.com/datatypes_global">
<Request>
<ServiceHeader>
<MessageTime>2021-05-17T11:29:06+00:00</MessageTime>
<MessageReference>1234567890123456789012345678901</MessageReference>
<SiteID>CIMAXMLPI</SiteID>
<Password>3p7jW0tamq</Password>
</ServiceHeader>
<MetaData>
<SoftwareName>software name</SoftwareName>
<SoftwareVersion>1.10</SoftwareVersion>
</MetaData>
</Request>
<LanguageCode>EN</LanguageCode>
<Billing>
<ShipperAccountNumber>359045226</ShipperAccountNumber>
<ShippingPaymentType>S</ShippingPaymentType>
<DutyPaymentType>R</DutyPaymentType>
</Billing>
<Consignee>
<CompanyName>MOHAMED AIT OULID</CompanyName>
<AddressLine>2717 ARLINGTON DRIVE APART N 102 AL</AddressLine>
<AddressLine>ESCANDIRA VIRGINIA </AddressLine>
<City>ALEXANDRI</City>
<PostalCode>22306</PostalCode>
<CountryCode>US</CountryCode>
<CountryName>United States</CountryName>
<Contact>
<PersonName>MOHAMED AIT OULID </PersonName>
<PhoneNumber>17034779922</PhoneNumber>
</Contact>
<BusinessPartyTypeCode>BUSINESSPARTYTYPECODE</BusinessPartyTypeCode>
<RegistrationNumbers>
<RegistrationNumbers>
<Number>NUMBER</Number>
<NumberTypeCode>NUMBERTYPECODE</NumberTypeCode>
<NumberIssuerCountryCode>NUMBERISSUERCOUNTRYCODE</NumberIssuerCountryCode>
</RegistrationNumbers>
</RegistrationNumbers>
</Consignee>
<Dutiable>
<DeclaredValue>18.00</DeclaredValue>
<DeclaredCurrency>MAD</DeclaredCurrency>
<ShipperEIN>MA-BEN</ShipperEIN>
<TermsOfTrade>DDU</TermsOfTrade>
<Filing>
<filingType>FILINGTYPE</filingType>
<ITN>ITN</ITN>
</Filing>
</Dutiable>
<Reference>
<ReferenceID>46009000875384D</ReferenceID>
<ReferenceType>ID</ReferenceType>
</Reference>
<ShipmentDetails>
<CurrencyCode>MAD</CurrencyCode>
<Pieces>
<Piece>
<Weight>2.33</Weight>
<Depth>0</Depth>
<Width>0</Width>
<Height>0</Height>
<PieceID>1</PieceID>
<PackageType>EE</PackageType>
</Piece>
</Pieces>
<PackageType>EE</PackageType>
<Weight>2.376</Weight>
<DimensionUnit>C</DimensionUnit>
<WeightUnit>K</WeightUnit>
<GlobalProductCode>P</GlobalProductCode>
<LocalProductCode>P</LocalProductCode>
<Date>2021-05-17</Date>
<Contents>VETEMENTS ET BABOUCHES</Contents>
<IsDutiable>Y</IsDutiable>
</ShipmentDetails>
<Shipper>
<ShipperID>359045226</ShipperID>
<CompanyName>LOTFI HAYAT</CompanyName>
<AddressLine>HAY HANAA SOK HANA N 7 </AddressLine>
<City>CASABLANCA </City>
<PostalCode>20000</PostalCode>
<CountryCode>MA</CountryCode>
<CountryName>MOROCCO</CountryName>
<Contact>
<PersonName>LOTIF HAYAT </PersonName>
<PhoneNumber>0614183031</PhoneNumber>
</Contact>
</Shipper>
<SpecialService>
<SpecialServiceType>DS</SpecialServiceType>
</SpecialService>
<RegionCode>REGION CODE</RegionCode>
<RequestedPickupTime>N</RequestedPickupTime>
<NewShipper>N</NewShipper>
<UseDHLInvoice>Y</UseDHLInvoice>
<DHLInvoiceLanguageCode>en</DHLInvoiceLanguageCode>
<DHLInvoiceType>CMI</DHLInvoiceType>
<ExportDeclaration>
<ExportReason>sales</ExportReason>
<ExportReasonCode>P</ExportReasonCode>
<InvoiceNumber>MyDHLAPI - INV-001</InvoiceNumber>
<InvoiceDate>2021-04-29</InvoiceDate>
<TermsOfPayment>60 days</TermsOfPayment>
<PayerGSTVAT>yes</PayerGSTVAT>
<ReceiverReference>ReceiverReference</ReceiverReference>
<ExporterId>43244325</ExporterId>
<ExporterCode>ExporterCode</ExporterCode>
<InvoiceInstructions>This is invoice instruction</InvoiceInstructions>
<PlaceOfIncoterm>GAILDORF PORT</PlaceOfIncoterm>
<ShipmentPurpose>COMMERCIAL</ShipmentPurpose>
<DocumentFunction>IMPORT</DocumentFunction>
<InvoiceTotalNetWeight>0.400</InvoiceTotalNetWeight>
<InvoiceTotalGrossWeight>0.500</InvoiceTotalGrossWeight>
<CustomsDocuments>
<CustomsDocument>
<CustomsDocumentType>INV</CustomsDocumentType>
<CustomsDocumentID>MyDHLAPI - CUSDOC-001</CustomsDocumentID>
</CustomsDocument>
</CustomsDocuments>
<ExportLineItem>
<LineNumber>1</LineNumber>
<Quantity>1</Quantity>
<QuantityUnit>PCS</QuantityUnit>
<Description>Fall collection: knitted vegetarian top white US 5</Description>
<Value>56.525</Value>
<CommodityCode>6109.10.0010</CommodityCode>
<Weight>
<Weight>0.200</Weight>
<WeightUnit>K</WeightUnit>
</Weight>
<ManufactureCountryCode>MA</ManufactureCountryCode>
<ImportCommodityCode>6109.10.0010</ImportCommodityCode>
<ItemReferences>
<ItemReference>
<ItemReferenceType>PAN</ItemReferenceType>
<ItemReferenceNumber>10597122</ItemReferenceNumber>
</ItemReference>
</ItemReferences>
</ExportLineItem>
<InvoiceReferences>
<InvoiceReference>
<InvoiceReferenceType>OID</InvoiceReferenceType>
<InvoiceReferenceNumber>OID-7839749374</InvoiceReferenceNumber>
</InvoiceReference>
</InvoiceReferences>
</ExportDeclaration>
<NumberOfArchiveDoc>1</NumberOfArchiveDoc>
<RequestArchiveDoc>Y</RequestArchiveDoc>
<LabelImageFormat>PDF</LabelImageFormat>
<LAbel>
<HideAccount>N</HideAccount>
<LabelTemplate>8X4_thermal</LabelTemplate>
<Logo>Y</Logo>
</LAbel>
<GetPriceEstimate>N</GetPriceEstimate>
<SinglePieceImage>N</SinglePieceImage>
</req:ShipmentRequest>
我使用 jaxB API 中的 marchal 和 unmarchal 函数将我所有的 java 对象转换为 xml 请求
感谢您的帮助
解决方法很简单。
您需要添加一个 schemaVersion
属性 到您的根 class
并用 @XmlAttribute
注释,而不是 @XmlElement
.
@XmlAttribute(name = "schemaVersion")
private String schemaVersion;
// + getter and setter