FileInputStream与File的StreamSource问题

时间:2010-07-27 01:29:17

标签: xsd filestream

如果StreamSource(FileInputStream),但StreamSource(文件)确定

,则会出现SAX错误

嗨,当参数是FileInputStream时遇到了StreamSource问题。 当参数是File时,没关系。

 public int initXSD (String xsdFile) {

        // no error at all if File
  Source schemaFile = new StreamSource(new File(xsdFile));

        // sax error at newSchema() if FileInputStream
  Source schemaFile = new StreamSource( new FileInputStream(new File(xsdFile))); 

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


     Schema schema = factory.newSchema(schemaFile);
  validator = schema.newValidator();
  return 0;
 }

一旦我更改StreamSource行以获取FileInputStream:

Source schemaFile = new StreamSource( new FileInputStream(new File(xsdFile)));

我在newSchema()时遇到了sax错误:

org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 's:ComplexObjectType' to a(n) 'type definition' component.

1 个答案:

答案 0 :(得分:0)

public int initXSD (String xsdFile) {

    // no error at all if File 
    Source schemaFile = new StreamSource(new File(xsdFile));

    // sax error at newSchema() if FileInputStream 
    Source schemaFile = new StreamSource( new FileInputStream(new File(xsdFile))); 

    Schema schema = factory.newSchema(schemaFile); 
    validator = schema.newValidator(); 
    return 0;
}