Java/XML/SAXParserFactory

Материал из Java эксперт
Перейти к: навигация, поиск

Create SAXParser from SAXParserFactory

 
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
public class MainClass {
  public static void main(String args[]) throws Exception {
    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 = spf.newSAXParser();          
    System.out.println("Parser object is: "+ parser);
  }
}





is SAXParserFactory NamespaceAware

 
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
public class MainClass {
  public static void main(String args[]) throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    System.out.println("Parser will " + (spf.isNamespaceAware() ? "" : "not ")
        + "be namespace aware");
    System.out.println("Parser will " + (spf.isValidating() ? "" : "not ")
        + "validate XML");
    SAXParser parser = null;
    parser = spf.newSAXParser();
  }
}