junit unit 테스트에서 xml 파일의 유효성을 검사하려고합니다. 이것은 내 단순화 된 코드입니다. 스키마가 인해 내장되지 않는 그러나 스키마는 http://www.unece.org/ 및 http://www.gs1.org/단위 테스트에서 xsd 요소 이름이 확인되지 않음
package test;
import java.net.URL;
import java.nio.file.Paths;
import javax.xml.XMLConstants;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
public class Epcis11MessageCreatorForSoTest {
private static Schema schema;
private final static String[] XSD_FILES = {
"epcis11/xsd/BasicTypes.xsd",
"epcis11/xsd/DocumentIdentification.xsd",
"epcis11/xsd/Partner.xsd",
"epcis11/xsd/Manifest.xsd",
"epcis11/xsd/BusinessScope.xsd",
"epcis11/xsd/StandardBusinessDocumentHeader.xsd",
"epcis11/xsd/EPCglobal.xsd",
"epcis11/xsd/EPCglobal-epcis-1_1.xsd",
"epcis11/xsd/EPCglobal-epcis-query-1_1.xsd",
"epcis11/xsd/EPCglobal-epcis-masterdata-1_1.xsd",
};
@BeforeClass
public static void beforeClass() throws Exception {
try {
System.setProperty("jaxp.debug", "10");
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Source[] sources = new Source[XSD_FILES.length];
int i = 0;
for (String xsdfile : XSD_FILES) {
URL resource = Epcis11MessageCreatorForSoTest.class.getClassLoader().getResource(xsdfile);
String systemId = Paths.get(resource.toURI()).toFile().getAbsolutePath();
StreamSource ss = new StreamSource(
Epcis11MessageCreatorForSoTest.class.getClassLoader().getResourceAsStream(xsdfile),systemId);
sources[i] = ss;
i++;
}
schema = schemaFactory.newSchema(sources);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testFoo() {
Assert.assertTrue(true);
}
}
에서 액세스 할 수 있습니다 :
대상/테스트 클래스/epcis11/XSD/EPC 글로벌-EPCIS - 1_1.xsd; lineNumber : 46; columnNumber : 60; src-resolve : 'sbdh : StandardBusinessDocumentHeader'를 (n) '요소 선언'구성 요소로 해석 할 수 없습니다.
관련 라인은
내가 IDE와 프로젝트로 Eclipse를 사용
<xsd:schema xmlns:epcis="urn:epcglobal:epcis:xsd:1" xmlns:sbdh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader" xmlns:epcglobal="urn:epcglobal:xsd:1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:epcglobal:epcis:xsd:1" elementFormDefault="unqualified" attributeFormDefault="unqualified" version="1.1">
...
<xsd:import namespace="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader" schemaLocation="./StandardBusinessDocumentHeader.xsd"/>
...
<xsd:element ref="sbdh:StandardBusinessDocumentHeader"/>
는 JRE 시스템 라이브러리로 JavaSE-1.7을 사용하여이 (EPC 글로벌-EPCIS-1_1.xsd)처럼 보인다. 이 xsd 파일을 볼 때 구문 적으로 괜찮습니다. 그것은 내가 ide에서 xml 관련 오류를 얻지 못한다. 테스트가 ide 또는 maven에서 실행될 때 정확히 동일한 오류가 나타납니다.
내 schemafactory 또는 xsd 소스가 Java 객체로 잘못되었을 수있는 사항에 대한 제안 사항이 있습니까?
'sbdh'네임 스페이스는 어디에 정의되어 있습니까? –
네임 스페이스 접두사 'sbdh'는 EPCglobal-epcis-1_1.xsd에 있습니다. 위 줄의 미리보기가 있습니다. – user7040845