に絶対化されてからのEntityResolver#のresolveEntityの「システムID」(文字列のpublicId、文字列のシステムID)を防止するためにどのように私はそれにすべてのエンティティを解決するには、次のXML文書を解析したい:Javaは:現在の作業ディレクトリ
<!DOCTYPE doc SYSTEM 'mydoc.dtd'>
<doc>&title;</doc>
私はDOM(DocumentBuilderの)とSAX(XMLReaderの)を使用して、両方を試し
private static class MyEntityResolver
{
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException
{
// At this point, systemId is always absolutized to the current working directory,
// even though the XML document specified it as relative.
// E.g. "file:///H:/mydoc.dtd" instead of just "mydoc.dtd"
// Why??? How can I prevent this???
SgmlEntity entity = findEntityFromDatabase(systemId);
InputSource is = new InputSource(new ByteArrayInputStream(entity.getContents()));
is.setPublicId(publicId);
is.setSystemId(systemId);
return is;
}
}
:
は私のEntityResolverは、データベースから所定のシステムIDと外部エンティティをフェッチした後、解像度を行い、例示のために以下を参照のことになっていますエンティティリゾルバをMyEntに設定するityResolver(つまり、 setEntityResolver(new MyEntityResolver())
)、MyEntityResolver#resolveEntity(String publicId, String systemId)
のsystemId
は、常に現在の作業ディレクトリに絶対化されています。
私もsetFeature("http://xml.org/sax/features/resolve-dtd-uris", false);
を呼び出そうとしましたが、それは何の助けにもなりませんでした。
どのようにして私が望むものを達成できますか?
ありがとうございます! the EntityResolver Javadocsから