有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java InputStream在验证javax后为空。xml。验证。验证器;

我不明白为什么在下面的源代码中的validate指令之后,InputStream参数是空的

    public boolean validateXMLSchema(InputStream xmlStream) {
        try {
            XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(xmlStream);

            reader = new StreamReaderDelegate(reader) {
                public int next() throws XMLStreamException {
                    int n = super.next();
                    return n;
                }
            };

            SchemaFactory factory =
                    SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Schema schema = factory.newSchema(new StreamSource(getClass().getResourceAsStream("/xsd_example.xsd")));
            Validator validator = schema.newValidator(); 
            validator.validate(new StAXSource(reader));  //InputStream empty after this instruction
        } catch (SAXException | IOException | XMLStreamException e) {
            throw new RuntimeException("Error message...", e);

        }
        return true;
    }

谁能帮帮我吗

提前谢谢, 米卡


共 (0) 个答案