首页 > 解决方案 > xpath:前缀必须解析为命名空间:xsd

问题描述

我是使用 jaxb2 的新手。我收到此错误:“xpath:前缀必须解析为命名空间:xsd”,我不知道如何修复它。这是因为我有两个 xsd 文件试图设计同一个类但在我的 java 应用程序的不同包中

<jxb:bindings schemaLocation="../documentazione/xsd/Global/datatypes_global_v62.xsd">

        <jxb:schemaBindings>
            <jxb:package name="com.companyname.plugin.entities.global" />
        </jxb:schemaBindings>

        <jxb:bindings node="//xsd:complexType[@name='Contact']">
            <jxb:class name="GlobalContact" />
        </jxb:bindings>

    </jxb:bindings>


    <jxb:bindings schemaLocation="../documentazione/xsd/Global/pickupdatatypes_global-3.0.xsd">
        <jxb:schemaBindings>
            <jxb:package name="com.companyname.plugin.entities.pickup" />
        </jxb:schemaBindings>
        <jxb:bindings node="xsd://complexType[@name='contact']" >
            <jxb:class name="Contact" />
        </jxb:bindings>
    </jxb:bindings>

我已经尝试运行该插件,但我不知道如何修复该错误。

标签: javamavenbindingnamespacesjaxb

解决方案


我如何解决问题?简单的!在我使用的 xjb 文件的名称空间中:

    xmlns:xs="http://www.w3.org/2000/10/XMLSchema-instance"
    xs:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd">```

And this was fine for most of my xjb files, but in my case I want to use complexType node. In this case I have to use: 
```<jxb:bindings version="2.0"  xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xs="http://www.w3.org/2000/10/XMLSchema-instance"
    xs:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd">```

the `xmlns:xsd="http://www.w3.org/2001/XMLSchema` help me to fix all my issue.

推荐阅读