2010-07-27 39 views
1

SAX错误,如果StreamSource的(的FileInputStream),但StreamSource的(文件)确定StreamSource的问题的FileInputStream VS文件

您好,我遇到了一个问题的StreamSource当参数为的FileInputStream。 当参数是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()得到了一个萨克斯错误:

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

回答

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; 
} 
相关问题