1
나는 다음과 같은 XML 내용이 있습니다XML 유효성 검사가 실패하는 이유는 무엇입니까?
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(schemaFile);
Validator validator = schema.newValidator();
validator.validate(xmlFile);
: 나는 다음과 같은 코드를 사용하여 검증을 위해
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
targetNamespace="http://bioontology.org/bioportal/classBeanSchema#"
xmlns:c="http://bioontology.org/bioportal/classBeanSchema#">
<xs:element name="success">
<xs:complexType>
<xs:sequence>
<xs:element ref="c:accessedResource"/>
<xs:element ref="c:accessDate"/>
<xs:element ref="c:data"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="accessedResource" type="xs:string"/>
<xs:element name="accessDate" type="xs:string"/>
<xs:element name="data">
<xs:complexType>
<xs:all>
<xs:element ref="c:list" minOccurs="0" maxOccurs="1"/>
<xs:element ref="c:classBean" minOccurs="0" maxOccurs="1"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="classBean">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="c:fullId" maxOccurs="1" minOccurs="0"/>
<xs:element ref="c:id" maxOccurs="1" minOccurs="0"/>
<xs:element ref="c:label" maxOccurs="1" minOccurs="0"/>
<xs:element ref="c:relations" maxOccurs="1" minOccurs="0"/>
<xs:element name="type" type="xs:string" maxOccurs="1" minOccurs="0"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="fullId" type="xs:string"/>
<xs:element name="id" type="xs:string"/>
<xs:element name="label" type="xs:string"/>
<xs:element name="relations">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" ref="c:entry"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="entry">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="string" type="xs:string"/>
<xs:element ref="c:list"/>
</xs:choice>
<xs:element minOccurs="0" ref="c:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="list">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element minOccurs="0" maxOccurs="unbounded" ref="c:classBean"/>
<xs:element minOccurs="0" maxOccurs="unbounded" name="string" type="xs:string"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="int" type="xs:integer"/>
</xs:schema>
: 나는 다음과 같은 XML 스키마를 사용하여 유효성을 검사 할
<?xml version="1.0" encoding="UTF-8"?>
<success>
<accessedResource>/bioportal/provisional</accessedResource>
<accessDate>2013-04-23 20:50:58.139 PDT</accessDate>
<data>
<classBean>
<id>http://purl.bioontology.org/ontology/provisional/9cc8b147-e193-4d23-a3a1-9da34eeeb5a9</id>
<fullId>http://purl.bioontology.org/ontology/provisional/9cc8b147-e193-4d23-a3a1-9da34eeeb5a9</fullId>
<label>OzbbBugGbIINcdpSY</label>
<synonyms>
<string>ux0fBN http://www.ggiodpc.com/www.6shpFpANPwYnffbs9P5rsRN67oJWDZuQ.com.php</string>
</synonyms>
<definitions>
<string>ux0fBN http://www.ggiodpc.com/www.6shpFpANPwYnffbs9P5rsRN67oJWDZuQ.com.php</string>
</definitions>
<relations>
<entry>
<string>provisionalRelatedNoteId</string>
<string>Note_3df7809d-aac8-4cf8-b320-f3eecceacd4e</string>
</entry>
<entry>
<string>provisionalTermStatus</string>
<null/>
</entry>
<entry>
<string>provisionalCreated</string>
<date>2013-04-09 20:06:23.79 PDT</date>
</entry>
<entry>
<string>provisionalPermanentId</string>
<null/>
</entry>
<entry>
<string>provisionalRelatedOntologyIds</string>
<list>
<int>1057</int>
</list>
</entry>
<entry>
<string>provisionalSubmittedBy</string>
<int>38382</int>
</entry>
<entry>
<string>provisionalUpdated</string>
<null/>
</entry>
<entry>
<string>provisionalSubclassOf</string>
<org.openrdf.model.URI>
<uriString>http://purl.bioontology.org/ontology/RID/RID0</uriString>
<localNameIdx>-1</localNameIdx>
</org.openrdf.model.URI>
</entry>
</relations>
</classBean>
</data>
</success>
을
다음 예외가 throw되어 XML 파일이 스키마가 주어진 경우 유효하지 않음을 나타냅니다.
org.xml.sax.SAXParseException; systemId: file:/C:/xml.xml; lineNumber: 2; columnNumber: 10; cvc-elt.1: Cannot find the declaration of element 'success'.
2 행에서 'success'요소를 찾을 수 있기 때문에 메시지를 이해할 수 없습니다. 누군가 도움이 될 수 있습니까?
스키마에서 'success'다음에 오는 모든 요소를 대신 입력해야합니다. – leppie