Source Code : Intercepting All Accesses to External Entities During XML SAX Parsing
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Intercepting All Accesses to External Entities During XML SAX Parsing
import java.io.File;
import java.io.FileReader;
import java.net.URI;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
public class Main {
public static void main(String[] argv) throws Exception {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
builder.setEntityResolver(new MyResolver());
Document doc = builder.parse(new File("infilename.xml"));
}
}
class MyResolver implements EntityResolver {
public InputSource resolveEntity(String publicId, String systemId) {
try {
URI uri = new URI(systemId);
if ("file".equals(uri.getScheme())) {
String filename = uri.getSchemeSpecificPart();
return new InputSource(new FileReader(filename));
}
} catch (Exception e) {
}
return null;
}
}
Thank with us