问题描述
用JAXP解析XML时factory.setValidating(true);这行代码敲上报警告,不敲没问题,为什么,这是打开什么验证?packagecn.itcast.day003;importjavax.xml.parsers.*;importorg.w3c.dom.Document;importorg.xml.sax.ErrorHandler;importorg.xml.sax.SAXException;importorg.xml.sax.SAXParseException;importjava.io.*;/****使用JAXP解析XML文档的工具类**/publicclassXMLUtilsimplementsErrorHandler{privatefinalstaticStringurl="./src/cn/itcast/day003/users.xml";privatestaticDocumentdom;static{System.out.println("开始进行解析");try{DocumentBuilderFactoryfactory=DocumentBuilderFactory.newInstance();//打开确认选项,关闭名称空间敏感性选项//factory.setValidating(true);//factory.setNamespaceAware(false);DocumentBuilderbuilder=factory.newDocumentBuilder();Documentdom=builder.parse(newFile(url));}catch(Exceptione){thrownewRuntimeException(e.getMessage(),e);}}publicstaticDocumentgetDocment(){returndom;}@Overridepublicvoiderror(SAXParseExceptionexception)throwsSAXException{System.out.println("errormessage");}@OverridepublicvoidfatalError(SAXParseExceptionexception)throwsSAXException{//TODOAuto-generatedmethodstub}@Overridepublicvoidwarning(SAXParseExceptionexception)throwsSAXException{//TODOAuto-generatedmethodstub}publicstaticvoidmain(String[]args){newXMLUtils();}}
解决方案
本帖最后由 answer76 于 2011-07-22 14:28:38 编辑