Java无法解析符号xsd文件

问题描述 投票:0回答:1

我有以下 .xsd 文件:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:tns="http://soapexercise.plonca.sri.pja.edu/employees"
           targetNameSpace="http://soapexercise.plonca.sri.pja.edu/employees"
           elementFormDefault="qualified">

    <xs:complexType name="employeeDto">
        <xs:sequence>
            <xs:element name="id" type="xs:decimal" minOccurs="0"/>
            <xs:element name="firstName" type="xs:string"/>
            <xs:element name="lastName" type="xs:string"/>
            <xs:element name="birthDate" type="xs:date"/>
            <xs:element name="job" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>

    <xs:element name="getEmployeesResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="employees" type="tns:employeeDto" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

IntelliJ 说

tns:employeeDto
无法解析。如果我尝试在文件上运行
jaxb2:xjc
插件,我会得到以下堆栈跟踪:(此处有完整日志

org.xml.sax.SAXParseException: s4s-att-not-allowed: Attribute 'targetNameSpace' cannot appear in element 'schema'.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException (ErrorHandlerWrapper.java:204)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error (ErrorHandlerWrapper.java:135)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError (XMLErrorReporter.java:396)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr (XSDHandler.java:4253)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaError (XSDHandler.java:4236)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSAttributeChecker.reportSchemaError (XSAttributeChecker.java:1573)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSAttributeChecker.checkAttributes (XSAttributeChecker.java:1105)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSAttributeChecker.checkAttributes (XSAttributeChecker.java:960)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDocumentInfo.<init> (XSDocumentInfo.java:106)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.constructTrees (XSDHandler.java:823)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema (XSDHandler.java:652)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema (XMLSchemaLoader.java:617)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar (XMLSchemaLoader.java:576)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadGrammar (XMLSchemaLoader.java:542)
    at com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory.newSchema (XMLSchemaFactory.java:276)
    at com.sun.tools.xjc.reader.xmlschema.parser.SchemaConstraintChecker.check (SchemaConstraintChecker.java:81)
    at com.sun.tools.xjc.ModelLoader.loadXMLSchema (ModelLoader.java:301)
    at com.sun.tools.xjc.ModelLoader.load (ModelLoader.java:121)
    at com.sun.tools.xjc.ModelLoader.load (ModelLoader.java:76)
    at com.sun.tools.xjc.Driver.run (Driver.java:324)
    at org.codehaus.mojo.jaxb2.javageneration.AbstractJavaGeneratorMojo.performExecution (AbstractJavaGeneratorMojo.java:475)
    at org.codehaus.mojo.jaxb2.AbstractJaxbMojo.execute (AbstractJaxbMojo.java:337)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)

我该怎么做才能解决

tns:employeeDto

java xml xsd
1个回答
1
投票

targetNameSpace
应该是
targetNamespace
。属性大小写错误,无效。

https://www.w3.org/TR/xmlschema-1/#Schema_details

© www.soinside.com 2019 - 2024. All rights reserved.