13
我想驗證xml文檔使用xsd模式文件存儲在我的設備上。 這裏是我的示例代碼:如何將InputStream轉換爲Source?
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));
問:我如何轉換的InputStream成的SchemaFactory :: newSchema方法所需的源?
嗯,也許http://developer.android.com/reference/javax/xml/transform/stream/StreamSource.html? – Selvin 2013-03-04 14:12:32