SAXParserFactory: setNamespaceAware(boolean awareness) : SAXParserFactory « javax.xml.parsers « Java by API






SAXParserFactory: setNamespaceAware(boolean awareness)

/*
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: isNamespaceAware()
2.SAXParserFactory: isValidating()
3.SAXParserFactory: newInstance()
4.SAXParserFactory: setFeature(String name, boolean value)
5.SAXParserFactory: setValidating(boolean validating)