SAXParserFactory: isNamespaceAware() : SAXParserFactory « javax.xml.parsers « Java by API






SAXParserFactory: isNamespaceAware()

/*
Parser will be namespace aware
Parser will validate XML
Parser object is: com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl@21b6d 
 */
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.SAXException;

public class MainClass {
  public static void main(String args[]) {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespaceAware(true);
    spf.setValidating(true);
    System.out.println("Parser will " + (spf.isNamespaceAware() ? "" : "not ")
        + "be namespace aware");
    System.out.println("Parser will " + (spf.isValidating() ? "" : "not ") + "validate XML");

    SAXParser parser = null;
    try {
      parser = spf.newSAXParser();
    } catch (ParserConfigurationException e) {
      e.printStackTrace(System.err);
    } catch (SAXException e) {
      e.printStackTrace(System.err);
    }
    System.out.println("Parser object is: " + parser);
  }
}


           
       








Related examples in the same category

1.SAXParserFactory: isValidating()
2.SAXParserFactory: newInstance()
3.SAXParserFactory: setFeature(String name, boolean value)
4.SAXParserFactory: setNamespaceAware(boolean awareness)
5.SAXParserFactory: setValidating(boolean validating)