Cannot run Xpath queries from JAVA in XML files having <DOCTYPE> tag -
i have made following method runs hard-coded xpath queries in hard-coded xml file. method works perfect 1 exception. xml files contains following tag
<!doctype workflowdefinition system "wfdef4.dtd">
when try run query in file following exception:
java.io.filenotfoundexception: c:\programfiles\code\other\xpath\wfdef4.dtd(the system cannot find file specified).
the question : what can instruct program not take under consideration dtd file? have noted path c:\programfiles\code\other\xpath\wfdef4.dtd 1 run application , not 1 actual xml file located.
thank in advace
here method:
public string evaluate(string expression,file file){ xpathfactory factory = xpathfactory.newinstance(); xpath = xpathfactory.newinstance().newxpath(); stringbuffer strbuffer = new stringbuffer(); try{ inputsource inputsource = new inputsource(new fileinputstream(file)); //evaluates expression nodelist nodelist = (nodelist)xpath.evaluate(expression, inputsource,xpathconstants.nodeset); //does other stuff, irrelevant question. (int = 0 ; <nodelist.getlength(); i++){ strbuffer.append(nodelist.item(i).gettextcontent()); } }catch (exception e) { e.printstacktrace(); } return strbuffer.tostring(); }
and answer :
xpath = xpathfactory.newinstance().newxpath(); documentbuilderfactory dbf = documentbuilderfactory.newinstance(); //add line ignore dth dtd dbf.setfeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
Comments
Post a Comment