【问题标题】:Cannot resolve the name to a(n) 'element declaration' component无法将名称解析为(n)“元素声明”组件
【发布时间】:2015-06-20 14:32:02
【问题描述】:

编译 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>

如果我按照异构命名空间设计http://www.xfront.com/ZeroOneOrManyNamespaces.html

中的建议使用 type 而不是 ref

我得到以下错误

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

【问题讨论】:

    标签: java xsd compilation maven-jaxb2-plugin


    【解决方案1】:

    CustomerApplicationDetail 是 complexType 而不是 element,因此您必须使用 typename。 在 A.xsd 中,试试这个修改:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-14
      • 1970-01-01
      • 1970-01-01
      • 2020-08-29
      • 1970-01-01
      • 2017-11-07
      • 2017-02-02
      • 1970-01-01
      相关资源
      最近更新 更多