开发者

StreamSource problem with FileInputStream vs File

开发者 https://www.devze.com 2023-01-09 04:16 出处:网络
SAX error if StreamSource(FileInputStream) but StreamSource(File) ok Hi, I encountered a StreamSource issue when the parameter was FileInputStream.

SAX error if StreamSource(FileInputStream) but StreamSource(File) ok

Hi, I encountered a StreamSource issue when the parameter was FileInputStream. When the parameter wa开发者_如何学JAVAs File, it's ok.

 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;
 }

as soon as i changed the StreamSource line to take a FileInputStream:

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

I got a sax error at newSchema():

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


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消