XML模式:无法解析名称类型定义

时间:2018-12-27 14:22:20

标签: java xml xsd jaxb xsd-validation

我正在定义架构,但是在eclipse中对其进行验证时,会出现以下错误。

  

[错误]:1125:55:src-resolve:无法将名称“ YesNoDoesNotApplyType”解析为一个(n)“类型定义”组件。

我的架构如下:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="9.00" id="R2014.1">
<xs:include schemaLocation="ATA_CommonTypes.xsd"/>

<xs:element name="ABT" type="YesNoDoesNotApplyType">
    <xs:annotation>
        <xs:documentation>Aborted Approach Indicator</xs:documentation>
    </xs:annotation>
</xs:element>

</xs:schema>

ATA_CommonTypes.xsd如下所示:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.00" id="R2007.1">

<xs:simpleType name="YesNoDoesNotApplyType">
    <xs:restriction base="xs:string">
        <xs:minLength value="1"/>
        <xs:maxLength value="1"/>
        <xs:enumeration value="D">
            <xs:annotation>
                <xs:documentation>Does Not Apply</xs:documentation>
            </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value="N">
            <xs:annotation>
                <xs:documentation>No</xs:documentation>
            </xs:annotation>
        </xs:enumeration>
        <xs:enumeration value="Y">
            <xs:annotation>
                <xs:documentation>Yes</xs:documentation>
            </xs:annotation>
        </xs:enumeration>
    </xs:restriction>
</xs:simpleType>
</xs:schema>

我的eclipse函数如下:并且它从下面的行给出了错误 XSModel模型= schemaLoader.load(输入);

private SchemaAlertFormatterUtil(String schemaUriBase) {
  try {
     InputStream schemaInputStream =
           this.getClass().getClassLoader().getResourceAsStream( schemaUriBase + CSDD_MM_XSD );
     DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
     XSImplementation xsImplementation =
           ( XSImplementation ) registry.getDOMImplementation( "XS-Loader" );

     XSLoader schemaLoader = xsImplementation.createXSLoader( null );
     LSInput input = new DOMInputImpl();
     input.setByteStream( schemaInputStream );
     XSModel model = schemaLoader.load( input );

     annotationBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
     // Read and add all element declarations
     XSNamedMap elements = model.getComponents( XSConstants.ELEMENT_DECLARATION );
     for ( int i = 0; i < elements.getLength(); i++ ) {
        XSElementDeclaration item = ( XSElementDeclaration ) elements.item( i );
        addItemToMapper( item.getName(), item.getAnnotation() );
     }

     // Read and add all attribute declarations
     XSNamedMap attributes = model.getComponents( XSConstants.ATTRIBUTE_DECLARATION );
     for ( int i = 0; i < attributes.getLength(); i++ ) {
        XSAttributeDeclaration item = ( XSAttributeDeclaration ) attributes.item( i );
        addItemToMapper( item.getName(), item.getAnnotation() );
     }
  } catch ( Exception exception ) {
     LOGGER.error( "Error occured when loading CSDD_MM.xsd", exception );
  }}

1 个答案:

答案 0 :(得分:0)

解释在于您没有给我们看的东西,而您没有给我们看的最重要的东西是模式文档的目标名称空间。如果架构文档具有目标名称空间,则类型将位于该名称空间中,并且对该类型的引用必须使用适当的前缀进行限定。

相关问题