java 如何将 InputStream 转换为 Source?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15203439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 18:50:44  来源:igfitidea点击:

How to convert InputStream into Source?

javaandroidvalidationxsd

提问by tommyk

I want to validate xmldocument using xsdschema file stored on my device. Here is my example code:

我想使用存储在我设备上的xsd架构文件验证xml文档。这是我的示例代码:

SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

// schema file on my device
InputStream isSchema = context.getResources().openRawResource(xsd_file);
// InputStream => Source conversion
Source schemaSource = ????
Schema schema = factory.newSchema(schemaSource);

Validator validator = schema.newValidator();
validator.validate(new DOMSource(document));

Question:How can I convert InputStream into Source required by SchemaFactory::newSchema method ?

问题:如何将 InputStream 转换为 SchemaFactory::newSchema 方法所需的 Source?