/我遇到了问题,因为我有三个引用的 xsd,我要验证一个作为 jdom 元素的 xml。我得到的例外是“找不到清除”。代码如下:输入参数为:元素参数/
DOMOutputter outputter = new DOMOutputter();
org.jdom2.Document document=new org.jdom2.Document();
document.addContent(param.clone());
org.w3c.dom.Document doc=outputter.output(document);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Source xmlSource = new DOMSource(doc);
Result outputTarget = new StreamResult(outputStream);
TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget);
InputStream xml = new ByteArrayInputStream(outputStream.toByteArray());
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
factory.setNamespaceAware(true);
builder = factory.newDocumentBuilder();
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// create a grammar object.
Source[] source = {
new StreamSource(new File("H:/ref2.xsd")),
new StreamSource(new File("H:/ref1.xsd")),
new StreamSource(new File("H:/ref.xsd"))};
Schema schemaGrammar = schemaFactory.newSchema(source);
validator.validate(new StreamSource(xml));
//请建议