DTD problem


XML & Web services: DTD problem

  1. DTD problem (1 messages)

    When I Use Xercerse package to parse a xml document which contains <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "https://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">. Because my computer is not connected to Internet, so "www.w3.org not found" exception is thrown. How to solve the problem?

    Threaded Messages (1)

  2. DTD problem[ Go to top ]

      You need to use the EntityResolver in order to resolve this to a copy of the DTD on your local file system.
     Below is the code required for you.....

    import javax.xml.parsers.*;
    import org.xml.sax.*;

    SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
    XMLReader xmlReader = saxParser.getXMLReader();
    MyResolver myResolver = new MyResolver();

    your class should be,
     import org.xml.sax.EntityResolver;
     import org.xml.sax.InputSource;

     public class MyResolver implements EntityResolver {
       public InputSource resolveEntity (String publicId, String systemId)
         if (systemId.equals("https://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd")
                 || publicId.equals("-//W3C//DTD SVG 1.0//EN")) {
               // return a special input source
               FileReader fileReader = new FileReader("/usr/home/work/dtds/svg10.dtd");
               return new InputSource(fileReader);
         } else {
                  // use the default behaviour
           return null;

    Hope it helps you...