I am writing a Java application for the postprocessing of XML files. These xml files come from an RDF-Export of a Semantic Mediawiki, so they have rdf/xml syntax.
My problem is the following: When I read the xml file, all the entities in the file get resolved to their value which is specified in the Doctype. For example in the Doctype I have
<!DOCTYPE rdf:RDF[
<!ENTITY wiki 'http://example.org/smartgrid/index.php/Special:URIResolver/'>
..
]>
and in the root element
<rdf:RDF
xmlns:wiki="&wiki;"
..
>
This means
<swivt:Subject rdf:about="&wiki;Main_Page">
becomes
<swivt:Subject rdf:about="http://example.org/smartgrid/index.php/Special:URIResolver/Main_Page">
I have tried using JDOM and the standard Java DOM. The code I think is relevant here is for standard DOM:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setExpandEntityReferences(false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
and for JDOM
SAXBuilder builder = new SAXBuilder();
builder.setExpandEntities(false); //Retain Entities
builder.setValidation(false);
builder.setFeature("http://xml.org/sax/features/resolve-dtd-uris", false);
But the Entities are resolved throughout the whole xml document none the less. Am I missing something? Hours of search has only led me to the 'ExpandEntities' commands, but they don't seem to work.
Any hint is highly appreciated :)