当前位置: 首页 > 知识库问答 >
问题:

遭遇JAXB-unmarshal XML异常

莘睿
2023-03-14

谁能帮我摆脱这个例外。

意外元素(uri:)http://cpps.xxx.com/splm-service,本地:“PartInquiryService”)。预期元素为(无)

下面是我正在使用的代码和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;
    }


}

共有1个答案

万俟丁雷
2023-03-14

添加类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中的命名空间在这种情况下是不必要的,但是我曾经加强了这个信息。

 类似资料:
  • Chapter One. The Linux server hosting our CVS repository (all our source code) fails. No big deal, it is automatically mirrored (usingrdist) to a remote location. It takes a few hours to compress and

  • constants.xml_path=“/acquirer.xml”;

  • 本文向大家介绍PHPCMS遭遇会员投稿审核无效的解决方法 原创,包括了PHPCMS遭遇会员投稿审核无效的解决方法 原创的使用技巧和注意事项,需要的朋友参考一下 今天接到主编那边的反馈,说本站的会员投稿平台,后台无法审核文章了,赶紧看看吧 本来想偷个懒,去度娘那里搜搜,看有相同情况的解决方案没,结果大失所望,虽然也有几个类似的情况,要么没解决,要么就是原因跟本站不同。 得了,毛主席他老人家教导我们,

  • 我试图解组xml导致saxparser异常,因为元素的值有一个未正确关闭的标记元素。这是我得到的,我必须处理的。 这里是示例xml- 上面的xml和其他字符串一起作为命令的值,标签没有正确关闭,导致以下异常- [org.xml.sax.saxpasseeption;行号:1;列号:212;元素类型“ctag”后面必须跟有属性规范,” 将xml输入作为字符串阅读器提供给unMarshall 我有两个

  • 我正在使用JAXB XMLadapter封送和反封送布尔值。应用程序的XML文件也将被C#应用程序访问。我们必须验证这个XML文件,这是使用XSD完成的。C#应用程序为布尔节点编写“true”值。但XSD也验证了这一点,因为它只允许“true/false”或“1/0”。因此,我们在XSD中保留了布尔值的String,该String将由XMLAdapter验证,以便在我们这边进行封送和反封送。XML

  • 问题内容: 我正在使用JAXB XMLadapter来编组和解组布尔值。C#应用程序也将访问该应用程序的XML文件。我们必须验证此XML文件,这是使用XSD完成的。C#应用程序为布尔节点写入“ True”值。但是我们的XSD确实验证了同样的结果,因为它只允许“ true / false”或“ 1/0”。因此,我们在XSD中将String保留为布尔值,并且XMLAdapter会验证该字符串是否在我们