Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JaxB解组错误:java.lang.RuntimeException:意外元素(uri:,local:“代码”)。预期元素为_Java_Jaxb - Fatal编程技术网

JaxB解组错误:java.lang.RuntimeException:意外元素(uri:,local:“代码”)。预期元素为

JaxB解组错误:java.lang.RuntimeException:意外元素(uri:,local:“代码”)。预期元素为,java,jaxb,Java,Jaxb,请告知此JAXB解组代码可能存在什么问题 这是我在尝试解组下面提供的XML时收到的错误消息: java.lang.RuntimeException:意外元素uri:,本地:代码。预期的要素是 使用基于XSD的JaxB,使用JDK1.7和EclipseIDE解析借款人类 : 问题在于xsd,因此生成的POJO和xml不匹配 例如,正如您在Borrower类中看到的,名称和代码用@XmlAttribute注释,但是您的xml没有将它们作为属性,而是作为元素 更具体地说,您的xml如下所示: <

请告知此JAXB解组代码可能存在什么问题 这是我在尝试解组下面提供的XML时收到的错误消息:

java.lang.RuntimeException:意外元素uri:,本地:代码。预期的要素是

使用基于XSD的JaxB,使用JDK1.7和EclipseIDE解析借款人类

:


问题在于xsd,因此生成的POJO和xml不匹配

例如,正如您在Borrower类中看到的,名称和代码用@XmlAttribute注释,但是您的xml没有将它们作为属性,而是作为元素

更具体地说,您的xml如下所示:

<borrower>
   <code>7777777777</code>
   <name>FirstName Surname LastName</name>
   <section>
    ...
</borrower>
但是POJO的构建期望类似这样的东西只关注代码和名称:

<borrower code="someCode" name="someName">
   <section>
    ...
</borrower>
继续下去,还有更多类似的问题。所以我们必须修复你的xsd。它在你的控制之下吗

如果您将xsd更改为下面的xsd,您将能够解组

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:wmh="http://www.wmhelp.com/2003/eGenerator"
           elementFormDefault="qualified">
    <xs:element name="borr-info-list">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="borrower" maxOccurs="unbounded"/>
                <xs:element name="req-file-name" type="xs:string"/>
                <xs:element name="req-file-time" type="xs:string"/>
                <xs:element name="req-file-user" type="xs:string"/>
                <xs:element name="req-file-entity" type="xs:string"/>
                <xs:element name="out-file-time" type="xs:string"/>
                <xs:element name="borr_count" type="xs:string"/>
            </xs:sequence>

        </xs:complexType>
    </xs:element>
    <xs:element name="borrower">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="section" maxOccurs="unbounded"/>
                <xs:element name="code" type="xs:string"/>
                <xs:element name="name" type="xs:string"/>
            </xs:sequence>

        </xs:complexType>
    </xs:element>
    <xs:element name="section">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="active-credits"/>
                <xs:element ref="overdue-history"/>
                <xs:element ref="new-credits"/>
                <xs:element name="entity-type" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="active-credits">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="summaries" maxOccurs="unbounded"/>
                <xs:element name="cred-count" type="xs:string"/>
                <xs:element name="source-entity-count" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="summaries">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="summary" maxOccurs="unbounded"/>
                <xs:element name="grouping-attribute" type="xs:string" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="summary">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="date-from" type="xs:string"/>
                <xs:element name="type" type="xs:string"/>
                <xs:element name="amount-approved" type="xs:string"/>
                <xs:element name="amount-drawn" type="xs:string"/>
                <xs:element name="monthly-installment" type="xs:string"/>
                <xs:element name="outstanding-performing-principal" type="xs:string"/>
                <xs:element name="outstanding-overdue-principal" type="xs:string"/>
                <xs:element name="balance-sheet-value" type="xs:string"/>
                <xs:element name="off-balance-sheet-value" type="xs:string"/>
                <xs:element name="overdue-payment-period" type="xs:string"/>
                <xs:element name="rest" type="xs:string"/>
                <xs:element name="term" type="xs:string"/>
                <xs:element name="active" type="xs:string"/>
                <xs:element name="year" type="xs:string"/>
                <xs:element name="category" type="xs:string"/>
                <xs:element name="months-count" type="xs:string"/>
                <xs:element name="max-cred-count" type="xs:string"/>
                <xs:element name="max-outstanding-overdue-principal" type="xs:string"/>
                <xs:element name="max-outstanding-overdue-interest-and-others"
                            type="xs:string"/>
                <xs:element name="max-off-balance-sheet-dues" type="xs:string"/>
                <xs:element name="date-last-correction" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="overdue-history">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="summary" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="new-credits">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="summary" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

非常感谢mart的快速响应,效果非常好:
<borrower>
   <code>7777777777</code>
   <name>FirstName Surname LastName</name>
   <section>
    ...
</borrower>
<borrower code="someCode" name="someName">
   <section>
    ...
</borrower>
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:wmh="http://www.wmhelp.com/2003/eGenerator"
           elementFormDefault="qualified">
    <xs:element name="borr-info-list">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="borrower" maxOccurs="unbounded"/>
                <xs:element name="req-file-name" type="xs:string"/>
                <xs:element name="req-file-time" type="xs:string"/>
                <xs:element name="req-file-user" type="xs:string"/>
                <xs:element name="req-file-entity" type="xs:string"/>
                <xs:element name="out-file-time" type="xs:string"/>
                <xs:element name="borr_count" type="xs:string"/>
            </xs:sequence>

        </xs:complexType>
    </xs:element>
    <xs:element name="borrower">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="section" maxOccurs="unbounded"/>
                <xs:element name="code" type="xs:string"/>
                <xs:element name="name" type="xs:string"/>
            </xs:sequence>

        </xs:complexType>
    </xs:element>
    <xs:element name="section">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="active-credits"/>
                <xs:element ref="overdue-history"/>
                <xs:element ref="new-credits"/>
                <xs:element name="entity-type" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="active-credits">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="summaries" maxOccurs="unbounded"/>
                <xs:element name="cred-count" type="xs:string"/>
                <xs:element name="source-entity-count" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="summaries">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="summary" maxOccurs="unbounded"/>
                <xs:element name="grouping-attribute" type="xs:string" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="summary">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="date-from" type="xs:string"/>
                <xs:element name="type" type="xs:string"/>
                <xs:element name="amount-approved" type="xs:string"/>
                <xs:element name="amount-drawn" type="xs:string"/>
                <xs:element name="monthly-installment" type="xs:string"/>
                <xs:element name="outstanding-performing-principal" type="xs:string"/>
                <xs:element name="outstanding-overdue-principal" type="xs:string"/>
                <xs:element name="balance-sheet-value" type="xs:string"/>
                <xs:element name="off-balance-sheet-value" type="xs:string"/>
                <xs:element name="overdue-payment-period" type="xs:string"/>
                <xs:element name="rest" type="xs:string"/>
                <xs:element name="term" type="xs:string"/>
                <xs:element name="active" type="xs:string"/>
                <xs:element name="year" type="xs:string"/>
                <xs:element name="category" type="xs:string"/>
                <xs:element name="months-count" type="xs:string"/>
                <xs:element name="max-cred-count" type="xs:string"/>
                <xs:element name="max-outstanding-overdue-principal" type="xs:string"/>
                <xs:element name="max-outstanding-overdue-interest-and-others"
                            type="xs:string"/>
                <xs:element name="max-off-balance-sheet-dues" type="xs:string"/>
                <xs:element name="date-last-correction" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="overdue-history">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="summary" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="new-credits">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="summary" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>