To solved this I've binned using batik's own parser and am using the DOM
LSParser instead.

The comments are still omitted, however but that is a minor issue. But I
think I'm onto a winner because with the DOM LSParser I've got full control
and not things hidden away or over customised as it seems with the batik
parser.

Here is the code. Following it is some class defs for resolved DTD locally.

Code is also discussed in separare thread:
http://www.nabble.com/Using-LSParser-with-Local-DTD-gives-exception%3A-Recursive-entity-reference-%22-svg-framework.mod%22-to16002292.html
"SOLVED - Re: Using LSParser with Local DTD gives exception: Recursive
entity reference "%svg-framework.mod""



/ part based on Oreilly Java and XML book



      File file = new File("C:\\myfile.svg");
     
      URI localFileAsUri = file.toURI();
     

     
          DOMImplementationRegistry registry =
                  DOMImplementationRegistry.newInstance( );
         
          DOMImplementationLS lsImpl =
                  (DOMImplementationLS)registry.getDOMImplementation("LS");
         
          LSParser parser =
                 
lsImpl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS,
                  null);
         
          // Set options on the parser
          DOMConfiguration config = parser.getDomConfig( );
          config.setParameter("validate", Boolean.TRUE);
         
           
         
          config.setParameter("resource-resolver", LocalDTDResolver );
         
         
          org.w3c.dom.Document doc =
parser.parseURI(localFileAsUri.toString());



import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;

import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSResourceResolver;

 public class LocalDTDResolver implements LSResourceResolver {
         
   String myLocalDTDFileAsString;
   URI localDTDFileAsUri;
   String myLocalDTDPath;
   LSInput LSInput;
         
   public LocalDTDResolver( String localDTDPath, String localSVGDTDFilename
) throws MalformedURLException
   {

           myLocalDTDPath = localDTDPath;
           
           myLocalDTDFileAsString = localDTDPath + localSVGDTDFilename;
       
        LSInput = new LSInput(myLocalDTDFileAsString );
   }
         
   public LSInput resolveResource(String type, String namespaceURI, String
publicId, String systemId, String baseURI)
   {
     //Allow the application to resolve external resources.
           
         // the occasion where systemId == null
         // is where the LSParser has finished looking at the
         // DTD and is now looking at the XML document itself
         // so at this point, make the systemid the same as the
         // baseuri - the XML document location
     if ( systemId == null )
     {
       System.out.println( "systemId:" + systemId );
                             
           LSInput.setSystemId( baseURI );
           LSInput.setPublicId( null );
           LSInput.setBaseURI( baseURI );

           return LSInput;
         }

         if (systemId.endsWith("mydtd.dtd"))
         {
           return LSInput;
         }
         else
         {
           System.out.println( "myLocalDTDPath + systemId:" + myLocalDTDPath
+ systemId );
                 
           LSInput.setSystemId( myLocalDTDPath + systemId );
         
           return LSInput;
         }  
   }
 }
 
 
 /*
 System.out.println( "\nDEBUG" );
 System.out.println( "type: " + type );
 System.out.println( "namespaceURI:" + namespaceURI );
 System.out.println( "publicId:" + publicId );
 System.out.println( "systemId:" + systemId );
 System.out.println( "baseURI:" + baseURI );
 System.out.println( "\n" ); 
*/
-- 
View this message in context: 
http://www.nabble.com/DOCTYPE-and-COMMENTS-ignored-by-batik-parser-SAXSVGDocumentFactory-tp16001432p16024121.html
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to