将InputStream转换为Document时出现错误,我正在使用DocumentBuilder并按以下方式导入,但出现类型不兼容错误。
编码 :
import com.sun.xml.internal.txw2.Document; ////
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Scanner;
import javax.xml.parsers.DocumentBuilder; ////
import javax.xml.parsers.DocumentBuilderFactory; ////
public static Document parse(InputStream is) { // converting the resulted InputStream to a document
Document doc = null ;
DocumentBuilderFactory domFactory;
DocumentBuilder builder;
try {
domFactory = DocumentBuilderFactory.newInstance();
domFactory.setValidating(false);
domFactory.setNamespaceAware(false);
builder = domFactory.newDocumentBuilder();
doc = builder.parse(is); // I have the error here
} catch (Exception ex) {
System.err.println("unable to load XML: " + ex);
}
return doc;
}