我正在使用Java 5 javax.xml.validation.Validator來(lái)驗(yàn)證XML文件。我已經(jīng)完成了一個(gè)僅使用導(dǎo)入的架構(gòu),并且一切正常?,F(xiàn)在,我嘗試使用另一種使用導(dǎo)入和包含的模式進(jìn)行驗(yàn)證。我的問(wèn)題是主模式中的元素被忽略,驗(yàn)證表明它找不到它們的聲明。這里是我建的模式:InputStream includeInputStream = getClass().getClassLoader().getResource("include.xsd").openStream();InputStream importInputStream = getClass().getClassLoader().getResource("import.xsd").openStream();InputStream mainInputStream = getClass().getClassLoader().getResource("main.xsd").openStream();Source[] sourceSchema = new SAXSource[]{includeInputStream , importInputStream, mainInputStream };Schema schema = factory.newSchema(sourceSchema);現(xiàn)在這是main.xsd中聲明的摘錄<xsd:schema xmlns="http://schema.omg.org/spec/BPMN/2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:import="http://www.foo.com/import" targetNamespace="http://main/namespace" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xsd:import namespace="http://www.foo.com/import" schemaLocation="import.xsd"/> <xsd:include schemaLocation="include.xsd"/> <xsd:element name="element" type="tElement"/> <...></xsd:schema>如果我將包含的XSD的代碼復(fù)制到main.xsd中,則可以正常工作。如果沒(méi)有,驗(yàn)證將找不到“ Element”的聲明。
添加回答
舉報(bào)
0/150
提交
取消