|
Accessing features of the SAX parser implementation |
|
|
SAX is an interface specification from W3C. Since, it
may have different implementations, it defines specific
features and properties.
SAX-interface defines access to implementation-specific
features. Moreover, some common features are defined and
mandatory; and thus should be supported in all SAX parsers.
Example below shows how to get features supportes by XML-parser:
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.SAXNotRecognizedException;
/**
* This sample shows how to request the features
* current SAX-parser implementation supports.
*/
public class RequestFeaturesSample {
/**
* Application entry point
* @param args command-line arguments
*/
public static void main(String[] args) {
try {
// creates and returns new instance of SAX-implementation:
SAXParserFactory factory = SAXParserFactory.newInstance();
// all the features are represented by boolean values,
// indicating is each feature set (supported) or not:
String features[] = {
"http://xml.org/sax/features/namespaces",
"http://xml.org/sax/features/namespace-prefixes",
"http://xml.org/sax/features/string-interning",
"http://xml.org/sax/features/validation",
"http://xml.org/sax/features/external-general-entities",
"http://xml.org/sax/features/external-parameter-entities",
"http://xml.org/sax/features/lexical-handler/parameter-entities",
};
// request the values of all the features:
System.out.println("SAX features:");
for (int i = 0; i < features.length; i++) {
System.out.print("\t- '" + features[i] + "' is ");
try {
System.out.println("'" +
factory.getFeature(features[i]) + "'");
} catch (SAXNotRecognizedException ex) {
System.out.println("not supported");
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.