Tôi gặp sự cố khi cố xác thực đối tượng bằng xsd đã cho. Các lớp học đã được tạo từ xsd.JAXB - SAXParseException Không thể tìm thấy phần khai báo của phần tử
SchemaFactory factory = SchemaFactory
.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = factory.newSchema(getClass().getResource("/xsd/test.xsd"));
JAXBContext context = JAXBContext.newInstance(aClass);
Unmarshaller u = context.createUnmarshaller();
u.setSchema(schema);
Object anObject = u.unmarshal(new StreamSource(new StringReader(
MESSAGE)), aClass);
Dưới đây là thông điệp ngoại lệ
[org.xml.sax.SAXParseException: cvc-elt.1: Không thể tìm thấy việc kê khai của nguyên tố 'ACCESREFUSE'.]
Đây là XSD :
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="./include/CJCommon.xsd"/>
<xs:element name="ACCESREFUSE">
<xs:complexType>
<xs:sequence maxOccurs="1" minOccurs="1">
<!-- Entete -->
<xs:element maxOccurs="1" minOccurs="1" ref="IDOper"/>
<xs:element maxOccurs="1" minOccurs="1" ref="DateEvt"/>
<xs:element maxOccurs="1" minOccurs="1" ref="IDEvt"/>
<xs:element maxOccurs="1" minOccurs="1" ref="IDJoueur"/>
<xs:element maxOccurs="1" minOccurs="1" ref="HashJoueur"/>
<xs:element maxOccurs="1" minOccurs="1" ref="IDSession"/>
<xs:element maxOccurs="1" minOccurs="1" ref="IPJoueur"/>
<xs:element maxOccurs="1" minOccurs="0" ref="IDCoffre"/>
<!-- Corps -->
<xs:element maxOccurs="1" minOccurs="1" ref="TypAg"/>
<xs:element maxOccurs="1" minOccurs="0" name="CauseRefus" type="string-1024"/>
<xs:element maxOccurs="1" minOccurs="0" name="TypeRefus">
<xs:simpleType>
<xs:restriction base="string-1024">
<xs:enumeration value="DelaiIdentite"/>
<xs:enumeration value="RejetIdentite"/>
<xs:enumeration value="Interdit"/>
<xs:enumeration value="AutoInterdit"/>
<xs:enumeration value="OpVerrouille"/>
<xs:enumeration value="Verrouille"/>
<xs:enumeration value="Cloture"/>
<xs:enumeration value="Autre"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Phần tử ACCESREFUSE là gốc của xml.
XML:
<ACCESREFUSE>
<dateEvt>Tue Oct 15 11:45:48 CEST 2013</dateEvt>
<hashJoueur>0000000000000000000000000000000000000000</hashJoueur>
<typAg>JC</typAg>
<causeRefus>Interdit</causeRefus>
<typeRefus>Interdiction Temporaire</typeRefus>
<idjoueur>81.252.190.129</idjoueur>
<idoper>002</idoper>
<idsession>301090</idsession>
<idevt>0</idevt>
<ipjoueur/>
<idcoffre/>
</ACCESREFUSE>
Bất kỳ ý tưởng? Cảm ơn bạn
Vâng, điều này là lạ vì xác thực đã làm việc trước lỗi. Chỉ khi mọi thứ đều ổn, tôi có lỗi với phần tử gốc. Tôi đã thử với InputStream nhưng kết quả là cùng một – BkSouX
trước khi ngoại lệ, xác thực đã làm việc khi XML không chính xác. ví dụ nó nói với tôi để thay đổi lĩnh vực ... – BkSouX
có nó làm việc nhờ. vấn đề là trong CJCommon :) Cảm ơn sự giúp đỡ của bạn! – BkSouX