How do I get a non-null named argument using the org.xml.sax.ext.EntityResolver2 resolveEntity method?
In Java SAX processing, the point is that I cannot get the entity reference names from
org.xml.sax.ext.EntityResolver2
the resolveEntity method. The name argument is always null
, even if the documentation states that 'name' is never null when invoked by a SAX2 parser
.
Any idea?
To demonstrate the problem, I created a Jython 2.5 script. It prints (on my box):
Entity Resolver 2 enabled: True
Entity name: None
Jython 2.5 script:
# Jython
from org.python.core.util import StringUtil
from jarray import array
# Java Standard Edition
from org.xml.sax import *
from org.xml.sax.ext import *
from org.xml.sax.helpers import *
from java.io import ByteArrayInputStream
xml = """\
<!DOCTYPE doc
[<!ENTITY entity SYSTEM "entity-file">
]>
<doc>&entity;</doc>
"""
def empty_source():
_source = InputSource()
byte_stream = ByteArrayInputStream(array([], "b"))
_source.setByteStream(byte_stream)
return _source
class Handler(EntityResolver2):
def getExternalSubset(self, name, baseURI):
return None
def resolveEntity(self, name, publicId, baseURI, systemId):
print "Entity name:", name
return empty_source()
reader = XMLReaderFactory.createXMLReader()
enabled = reader.getFeature("http://xml.org/sax/features/use-entity-resolver2")
print "Entity Resolver 2 enabled:", enabled
handler = Handler()
reader.setEntityResolver(handler)
bytes = StringUtil.toBytes(xml)
byte_stream = ByteArrayInputStream(bytes)
source = InputSource(byte_stream)
reader.parse(source)
+1
source to share