gpt4 book ai didi

java - 坚持使用 JAXB - 解码 XML 异常

转载 作者:数据小太阳 更新时间:2023-10-29 01:56:30 29 4
gpt4 key购买 nike

谁能帮我摆脱这个异常。

unexpected element (uri:"http://cpps.xxx.com/splm-service", local:"PartInquiryService"). Expected elements are (none)

这是我使用的代码和xml

 File file = new File("PartInquiryService.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(PartInquiryService.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
PartInquiryService partInqService =
(PartInquiryService)jaxbUnmarshaller.unmarshal(file);

这是我正在使用它的 xml ..我将从 MQ 获取这个 xml 作为响应

<PartInquiryService xmlns="http://cpps.xxx.com/splm-service" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<control>
<type>inquiryWithServiceWindow</type>
<correlationId format="hex">A10488237F3B7734A10488237F3B7734A10488237F3B7734</correlationId>
<origin>
<system>CPPS-SPLM</system>
<id>MP2ZCP5</id>
<at timeZone="UTC">
<date format="ISO">2008-12-12</date>
<time format="ISO">20:12:48</time>
</at>
</origin>
<destination>
<system>SPLM_GUI</system>
<id>SPLM_01</id>
</destination>
</control>
<partInquiry>
<customerSystemkey>123456789123456</customerSystemkey>
<countryCode type="IBM">788</countryCode>
<partnumber>0000039M5123</partnumber>
<machType>1722</machType>
<zipcode>1066 VH</zipcode>
</partInquiry>
<inquiryResult>
<errorMessage>Invalid part number XXXXXXXXXXXX received</errorMessage>
<zipcodeUsed>NL 1066</zipcodeUsed>
<timeZone>MSK</timeZone>
<currency>EUR</currency>
<partnumber>
<id>0000039M5123</id>
<subType>REQ</subType>
<description>POWER CORD</description>
<subRank>0</subRank>
<weigth>10</weigth>
<length>12</length>
<width>9</width>
<height>11</height>
<sellingPrice currency="EUR">12.030</sellingPrice>
<rohsInd>C</rohsInd>
</partnumber>
<partnumber>
<id>0000040K8888</id>
<subType>ALT</subType>
<description>POWER CORD</description>
<subRank>0</subRank>
<weigth>10</weigth>
<length>12</length>
<width>9</width>
<height>11</height>
<sellingPrice currency="EUR">12.030</sellingPrice>
<rohsInd>D</rohsInd>
</partnumber>
<partnumber>
<id>0000012J1234</id>
<subType>SUB</subType>
<description>POWER CORD</description>
<subRank>-1</subRank>
<weigth>10</weigth>
<length>12</length>
<width>9</width>
<height>11</height>
<sellingPrice currency="EUR">12.030</sellingPrice>
<rohsInd>N</rohsInd>
</partnumber>
<sourceLocation>
<locId>788-5000</locId>
<description>CENTRAL BUFFER VENLO</description>
<deliveryOption>
<serviceWindow>Sameday 2hr</serviceWindow>
<logisticCost>88.00</logisticCost>
<date format="ISO">2014-08-24</date>
<time format="ISO">10:56:00</time>
</deliveryOption>
<deliveryOption>
<serviceWindow>Next day 16:00</serviceWindow>
<logisticCost>10.00</logisticCost>
<date format="ISO">2014-08-25</date>
<time format="ISO">16:00:00</time>
</deliveryOption>
<partInventory>
<id>0000039M5123</id>
<availableStock>1</availableStock>
</partInventory>
<partInventory>
<id>0000040K8888</id>
<availableStock>5</availableStock>
</partInventory>
</sourceLocation>
<sourceLocation>
<locId>821-9200</locId>
<description>CRS ST PETERSBURG</description>
<deliveryOption>
<serviceWindow>Sameday 2hr</serviceWindow>
<logisticCost>88.00</logisticCost>
<date format="ISO">2014-08-24</date>
<time format="ISO">10:56:00</time>
</deliveryOption>
<deliveryOption>
<serviceWindow>Next day 16:00</serviceWindow>
<logisticCost>10.00</logisticCost>
<date format="ISO">2014-08-25</date>
<time format="ISO">16:00:00</time>
</deliveryOption>
<partInventory>
<id>0000039M5123</id>
<availableStock>1</availableStock>
</partInventory>
<partInventory>
<id>0000040K8888</id>
<availableStock>5</availableStock>
</partInventory>
</sourceLocation>
<sourceLocation>
<locId>821-1102</locId>
<description>LSH MOSCOW DUTY PAID</description>
<deliveryOption>
<serviceWindow>Sameday 2hr</serviceWindow>
<logisticCost>88.00</logisticCost>
<date format="ISO">2014-08-24</date>
<time format="ISO">10:56:00</time>
</deliveryOption>
<deliveryOption>
<serviceWindow>Next day 16:00</serviceWindow>
<logisticCost>10.00</logisticCost>
<date format="ISO">2014-08-25</date>
<time format="ISO">16:00:00</time>
</deliveryOption>
<partInventory>
<id>0000039M5123</id>
<availableStock>1</availableStock>
</partInventory>
<partInventory>
<id>0000040K8888</id>
<availableStock>5</availableStock>
</partInventory>
</sourceLocation>
</inquiryResult>
</PartInquiryService>

这是 PartInquiryService.java

public class PartInquiryService {
private Control control;
private PartInquiry partInqury;
private InquiryResult inquiryResult;
public Control getControl() {
return control;
}
public void setControl(Control control) {
this.control = control;
}
public PartInquiry getPartInqury() {
return partInqury;
}
public void setPartInqury(PartInquiry partInqury) {
this.partInqury = partInqury;
}
public InquiryResult getInquiryResult() {
return inquiryResult;
}
public void setInquiryResult(InquiryResult inquiryResult) {
this.inquiryResult = inquiryResult;
}


}

最佳答案

在你的类上添加 PartInquiryService.java

@XmlRootElement(name = "PartInquiryService" ,namespace="http://cpps.xxx.com/splm-service")
public class PartInquiryService {

在同一个包中放置这个类(package-info.java)

@javax.xml.bind.annotation.XmlSchema(namespace = "http://cpps.xxx.com/splm-service", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package your.package;

注意:在这种情况下,@XmlRootElement 中的命名空间不是必需的,但我曾经强调过这一信息。

关于java - 坚持使用 JAXB - 解码 XML 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26774085/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com