xml - Cannot read XMLFile with exception: java.io.FileNotFoundException: C:\Temp\logger.dtd (The system cannot find the file specified) -


i having trouble reading xmlfile created class below. led believe there property here need set in order correct file directory used. xmlfile generated with:

<?xml version="1.0" encoding="windows-1252"?> <!doctype log system "logger.dtd"> 

at top can read if remove line containing "logger.dtd" . can explain going on? reading same uri set using saxparser api. followed instructions sax parsing here: http://www.mkyong.com/java/how-to-read-xml-file-in-java-sax-parser/

    package logging;      import java.io.ioexception;     import java.util.logging.filehandler;     import java.util.logging.handler;     import java.util.logging.level;     import java.util.logging.logger;      import java.util.logging.simpleformatter;     import java.util.logging.xmlformatter;      import javax.xml.parsers.saxparser;     import javax.xml.parsers.saxparserfactory;      import org.xml.sax.attributes;     import org.xml.sax.saxexception;     import org.xml.sax.helpers.defaulthandler;      public class log { static private filehandler filetxt; static private simpleformatter formattertxt; static private filehandler filexml; static private xmlformatter formatterxml;    static public void setup(logger thelogger) throws ioexception{     logger logger = thelogger;      logger.setlevel(level.all);      filetxt = new filehandler("c:\\temp\\logging.txt");     filexml = new filehandler("c:\\temp\\xmllogging.xml");      formattertxt = new simpleformatter();     filetxt.setformatter(formattertxt);     logger.addhandler(filetxt);      formatterxml = new xmlformatter();     filexml.setformatter(formatterxml);     logger.addhandler(filexml);      for(handler h: logger.gethandlers()){         system.out.println(h.getformatter());     }   }  } 

...at top can read if remove line containing "logger.dtd" . can explain going on?

the error thrown because sax parser defaults validating , loading external dtd. if don't want disable validation:

    saxparserfactory factory = saxparserfactory.newinstance();     factory.setfeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);     saxparser saxparser = factory.newsaxparser(); 

sax no longer dtd file , not throw file not found exception.

otherwise, "logger.dtd" file can found in java logging overview under 3.0 appendix a: dtd xmlformatter output.

<!-- dtd used java.util.logging.xmlformatter --> <!-- provides xml formatted log message. -->  <!-- document type "log" consists of sequence of record elements --> <!element log (record*)>  <!-- each logging call described record element. --> <!element record (date, millis, sequence, logger?, level, class?, method?, thread?, message, key?, catalog?, param*, exception?)>  <!-- date , time when logrecord created in iso 8601 format --> <!element date (#pcdata)>  <!-- time when logrecord created in milliseconds since midnight january 1st, 1970, utc. --> <!element millis (#pcdata)>  <!-- unique sequence number within source vm. --> <!element sequence (#pcdata)>  <!-- name of source logger object. --> <!element logger (#pcdata)>  <!-- logging level, may either 1 of constant names java.util.logging.level (such "severe" or "warning") or integer value such "20". --> <!element level (#pcdata)>  <!-- qualified name of class issued logging call, e.g. "javax.marsupial.wombat". --> <!element class (#pcdata)>  <!-- name of method issued logging call. may either unqualified method name such "fred" or may include argument type information in parenthesis, example "fred(int,string)". --> <!element method (#pcdata)>  <!-- integer thread id. --> <!element thread (#pcdata)>  <!-- message element contains text string of log message. --> <!element message (#pcdata)>  <!-- if message string localized, key element provides original localization message key. --> <!element key (#pcdata)>  <!-- if message string localized, catalog element provides logger's localization resource bundle name. --> <!element catalog (#pcdata)>  <!-- if message string localized, each of param elements provides string value (obtained using object.tostring()) of corresponding logrecord parameter. --> <!element param (#pcdata)>  <!-- exception consists of optional message string followed series of stackframes. exception elements used java exceptions , other java throwables. --> <!element exception (message?, frame+)>  <!-- frame describes 1 line in throwable backtrace. --> <!element frame (class, method, line?)>  <!-- integer line number within class's source file. --> <!element line (#pcdata)> 

you have copy text , place file named "logger.dtd" , place in same directory xml log files. sax parser able find file because exists.

you can find links searching logging package summary.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -