java - 无法将名称解析为 (n) 'element declaration' 组件

标签 java xsd compilation maven-jaxb2-plugin

编译 maven-jaxb2-plugin 时出现以下错误

[INFO] --- maven-jaxb2-plugin:0.8.3:generate (default) @ customer-project ---
   [ERROR] Error while parsing schema(s).Location [ file:....Customer.xsd{12,97}].
    org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'ttadcustomer:CustomerApplicationDetail' to a(n) 'element declaration' component.
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
        at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr(

A.xsd

<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://www.cohbe.org/CustomerRequest"
            xmlns:ttadcustomer="http://www.cohbe.org/customer"
            targetNamespace="http://www.cohbe.org/CustomerRequest"
            elementFormDefault="qualified">
    <xsd:import schemaLocation="TTAdDETAILS.xsd"
              namespace="http://www.cohbe.org/customer"/>
    <xsd:element name="CustomerNewRequest">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="ttadcustomer:CustomerApplicationDetail" minOccurs="0"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    ...
</xsd:schema>

这是 TTAdDETAILS.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema version="2.15" 
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://www.cohbe.org/customer"
            targetNamespace="http://www.cohbe.org/customer"
            xmlns:countries="http://www.cohbe.org/Counties"
            elementFormDefault="qualified">

    <xsd:complexType name="CustomerApplicationDetail">

    .....
    </xsd:schema>

如果我按照异构命名空间设计中的建议使用 type 而不是 ref http://www.xfront.com/ZeroOneOrManyNamespaces.html

我收到以下错误

One of 'ref' or 'name' must be present in a local element declaration.

最佳答案

CustomerApplicationDetail 是一个complexType,而不是一个元素,因此您必须使用typename。 在 A.xsd 中,尝试进行以下修改:

<xsd:element name = 'the_name_of_the_element' type = "ttadcustomer:CustomerApplicationDetail" minOccurs="0"/>

关于java - 无法将名称解析为 (n) 'element declaration' 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30955100/

相关文章:

java - 如何解析可能有或没有命名空间的 XML 内容?

unix - Automake:AM_CFLAGS 无效

java - 主要使用 javascript 和 JMeter 进行负载测试 Tapestry 应用程序

java - MongoDB 数字范围搜索无法按预期工作

java - 当属性名称为 ="value"时,将 xsd 转换为 java pojo 时出现问题

c++ - 在 C++ 上编译错误,未在此范围内声明 calcarea

windows - 如何使用 MinGW 和 MSYS 为 Windows 构建 Lua?

java - 如何在 fragment 中的 ListView 上显示数组?

java - PreparedStatement 不适用于 substring_index?

java - 元素中的 xsd 验证抛出内容类型异常