文档文档 = null; DocumentBuilder解析器 = DocumentBuilderFactory.newInstance().newDocumentBuilder(); 文档 = parser.paser(xmlFilePath);
解析异常 萨克斯异常 IO异常
SchemaFactory 架构 = SchemaFactory.newInstance(XMLConstanst.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(new Source []{new StreamSource(xsd1), new StreamSource(xsd2), new StreamSource(xsd3), newStreamSource(xsd4)})
验证器验证器 = schema.newValidator(); validator.setErrorHandler(new CustomHandler);
validator.validate(new DOMSource(文档);
SAXParseException cvc-elt.1 找不到元素“ElementinQuestion”的声明
字符串节点 = document.getNodeName();
节点=#文档
添加以下内容后,节点返回与上面相同的异常
字符串节点 = document.getFirstChildNode().getNodeName();
节点=“问题中的元素”
xsd
我还能检查什么?
添加了这一行,并在创建文档之前解决了异常 (发现这个向下滚动到底部 Cvc-elt.1:找不到元素“soap:Envelope”的声明)
Document document = null;
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setNamespaceAware(true);
DocumentBuilder parser = DocumentBuilderFactory.newInstance();
document = parser.paser(xmlFilePath);