XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] External subset processing by browsers

Hi Andrew,

Sorry, I spoke too soon. This works in oXygen and I thought it was just 
this feature... but we actually needed to work low level for that.

One trick that you can use is to take advantage of the fact that a 
parser in non validating mode is not required to actually read the DTD. 
You need to have a DTD specified though in the XML file. You will get 
the entity notification on the ContentHandler skippedEntity callback. 
See for instance the following class that gives the output below:

file:///D:/users/george/workspace/test/foo.dtd
Start ent: [dtd]
End ent: [dtd]
Skipped entity: euro


import java.io.IOException;
import java.io.StringReader;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.XMLFilterImpl;
import org.xml.sax.helpers.XMLReaderFactory;

public class Test extends XMLFilterImpl implements LexicalHandler {

   public static void main(String[] args) throws Exception {
     new Test();
   }

   public Test() throws Exception {
     String xml = "<!DOCTYPE foo SYSTEM 'foo.dtd'><foo>foo &euro; 
bar</foo>";
     XMLReader xmlReader = 
XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
 
xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler";, 
this);
     xmlReader.setEntityResolver(this);
     xmlReader.setContentHandler(this);
     xmlReader.parse(new InputSource(new StringReader(xml)));
   }

   public InputSource resolveEntity(String publicId, String systemId)
       throws SAXException, IOException {
     System.out.println(systemId);
     return new InputSource(new StringReader(""));
   }
   public void startDocument() throws SAXException {
     super.startDocument();
   }
   public void skippedEntity(String name) throws SAXException {
     System.out.println("Skipped entity: " + name);
   }
   public void startEntity(String name) throws SAXException {
     System.out.println("Start ent: " + name);
   }
   public void endEntity(String name) throws SAXException {
     System.out.println("End ent: " + name);
   }
   public void startCDATA() throws SAXException {}
   public void endCDATA() throws SAXException {}
   public void startDTD(String name, String publicId, String systemId) 
throws SAXException {}
   public void endDTD() throws SAXException {}
   public void comment(char[] ch, int start, int length) throws 
SAXException {}
}

Or you can just remove the fake resolver and use instead:
 
xmlReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd";, 
false);

that will give you as output
Skipped entity: euro

Hope that helps,
George
-- 
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Andrew Welch wrote:
> Hi George,
> 
> 2008/12/8 George Cristian Bina <george@oxygenxml.com>:
>> Try setting http://xml.org/sax/features/external-general-entities to false.
>> See also:
>> http://xerces.apache.org/xerces2-j/features.html#external-general-entities
> 
> Thanks, but same result.
> 
> Should this work? (maybe a problem with that verison of Xerces)   Or
> will it never work because of some fundamental dtd concept that
> sgml'ers all treat as common knowledge?    :)
> 
> 
> 


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS