Java 意外的JAXB错误

Java 意外的JAXB错误,java,xml,jaxb,Java,Xml,Jaxb,从文档中可以清楚地看出,我需要使用以下方法从XML文件/模式中进行简单的解组: JAXBContext jc = JAXBContext.newInstance("PackageName"); 其中PackageName是我的包名。我已经在谷歌上搜索了一段时间,但没有结果,我想知道为什么会出现这样的运行时错误: Line:Col[2:142]:cvc-elt.1: Cannot find the declaration of element 'myconfig'. Line:Col[2:142

从文档中可以清楚地看出,我需要使用以下方法从XML文件/模式中进行简单的解组:

JAXBContext jc = JAXBContext.newInstance("PackageName");
其中PackageName是我的包名。我已经在谷歌上搜索了一段时间,但没有结果,我想知道为什么会出现这样的运行时错误:

Line:Col[2:142]:cvc-elt.1: Cannot find the declaration of element 'myconfig'.
Line:Col[2:142]:unexpected element (uri:"http://www.w3.org", local:"myconfig"). Expected elements are <{}myconfig>
Caught UnmarshalException
那么,为什么会发生这种错误呢

编辑: 模式非常大,因此我不想将其全部粘贴到这里,因此ObjectFactory.java文件非常大。它开始了

package PackageName;

import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;
结束

/**
 * Create an instance of {@link JAXBElement }{@code <}{@link MyConfigType }{@code >}}
 * 
 */
@XmlElementDecl(namespace = "", name = "myconfig")
public JAXBElement<MyConfigType> createMyconfig(MyConfigType value) {
    return new JAXBElement<MyConfigType>(_Myconfig_QNAME, MyConfigType.class, null, value);
}
所以都很标准。我是一个XML模式新手,提供给我的模式的顶部是:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" attributeFormDefault="unqualified">
这也是直截了当的。根元素的架构如下所示:

<xs:complexType name="MyConfigType">
    <xs:sequence>
        <xs:element name="tips" type="TipType" minOccurs="0"
            maxOccurs="unbounded">
            <xs:key name="unique_abc_id">
                <xs:selector xpath="./abc" />
                <xs:field xpath="@id" />
            </xs:key>
            <xs:key name="unique_def_id">
                <xs:selector xpath="./def" />
                <xs:field xpath="@id" />
            </xs:key>
        </xs:element>
    </xs:sequence>
    <xs:attribute ref="noNamespaceschemaLocation" />
</xs:complexType>
我要求它在反汇编启动时同时验证提供的配置:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<myconfig xmlns="http://www.w3.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceschemaLocation="myconfig.xsd">
    <firsttag...>
我被难住了

编辑“结束”以使其正常工作:

JAXBContext jc = JAXBContext.newInstance("PackageName");
您需要具备以下一项或两项:

该目录中的ObjectFactory.class 一个jaxb.index文件。此文件应包含该包中的类名列表。
其中任何一个都将描述JAXB应该可以使用的类

啊。抱歉,忘了提一下,我已经让xjc创建了objectfactory.java文件——它与模式参考文件在一起。马克·刘易斯:我下一步要去哪里?我需要更多关于这些课程本身的信息。这看起来是一个模式验证问题,但在没有看到类的情况下,我不知道我是否可以告诉您很多。感谢您的回答,我已经在问题中编辑了一些问题代码,使其更加充实。也许这会更深入地说明我的问题。谢谢你
JAXBContext jc = JAXBContext.newInstance("PackageName");