【发布时间】:2014-09-30 05:02:23
【问题描述】:
我正在通过 Validator 类验证我的 jaxb 对象。下面是我用来验证 jaxb 对象的代码。但是在验证它时,我收到了这个错误。
jc = JAXBContext.newInstance(obj.getClass());
source = new JAXBSource(jc, obj);
Schema schema = schemaInjector.getSchema();
Validator validator = schema.newValidator();
validator.validate(source);
错误(SAXParseException):cvc-complex-type.2.4.a:发现以元素“ProcessDesc”开头的无效内容。应为 ProcessName 之一
我不明白我在 xsd 中做错了什么导致了这个错误。我的 xsd 文件中定义的元素在下面,我收到了错误。
<xs:schema xmlns:cc="http://www.ms.com/cm.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.ms.com/cm.xsd" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="Process">
<xs:sequence>
<xs:element name="ProcessId" type="xs:int" />
<xs:element name="ProcessName" type="xs:string" />
<xs:element name="ProcessDesc" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
请帮我解决这个问题。谢谢。
【问题讨论】: